Jump to content
  • Advertisement
Sign in to follow this  
D3DXVECTOR3

[VC++] undeclared identifier

This topic is 4850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im having this undeclared identifier error and i dont understand the reason for it. Here is my situation:
MyClassA:

MyClassA.h

#ifndef _MyClassA_H
#define _MyClassA_H

#include "MyClassB.h"

class MyClassA
{
public:
  MyClassA();
  ~MyClassA();

  void DoSomething();

private:
  vector<MyClassB> m_vClass; // MyClassB: undeclared identifier ????
};

#endif

MyClassA.cpp

#include "MyClassA.h"

MyClassA::MyClassA()
{

}

MyClassA::~MyClassA()
{

}

void MyClassA::DoSomething()
{

}

//---------------------------------------------------------------------

MyClassB:

MyClassB.h

#ifndef _MyClassB_H
#define _MyClassB_H

class MyClassB
{
public:
  MyClassB();
  ~MyClassB();

  void FunctionA();
  void FunctionB();

private:
  int iCount;
  string file;
};

#endif


MyClassB.cpp

#include "MyClassB.h"

MyClassB::MyClassB()
{

}


MyClassB::~MyClassB()
{

}

void MyClassB::FunctionA()
{

}

void MyClassB::FunctionB()
{

}


Share this post


Link to post
Share on other sites
Advertisement
Have you included vector and string in MyClassA.h and MyClassB.h respectively?
If so, since you don't have std:: infront of string and vector, do you have the line using namespace std; somewhere?

Share this post


Link to post
Share on other sites
Sounds like it might be a case of recursive includes, although the code you posted doesn't have that problem. Try replacing the #include directive in MyClassA.h with a forward declaration like so:

MyClassA:

MyClassA.h

#ifndef _MyClassA_H
#define _MyClassA_H

class MyClassB; // <-- forward declaration

class MyClassA
{
public:
MyClassA();
~MyClassA();

void DoSomething();

private:
vector<MyClassB> m_vClass; // MyClassB: undeclared identifier ????
};

#endif


Share this post


Link to post
Share on other sites
^^ thx man it worked :D

I thought that the ifndef-define-endif would prevents this!? both classes are inluding my log class so that could be the explanation, but i did this with all my code and this is the 1st time i saw this. Gues I still have some things to learn about including.

Share this post


Link to post
Share on other sites
Quote:
Original post by D3DXVECTOR3
I thought that the ifndef-define-endif would prevents this!?


Unfortunately not, the ifndef is to prevent it being included twice. On the plus side using a forward declaration means that changes in the header of the previous included class (MyClassB in this example) won't trigger recompilation of the including class (MyClassA in this example).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!