DIR Return Create A Forum - Home
---------------------------------------------------------
techsuns
HTML https://techsuns.createaforum.com
---------------------------------------------------------
*****************************************************
DIR Return to: OutPut of a Program
*****************************************************
#Post#: 207--------------------------------------------------
solve this problem...
By: dinesh Date: November 26, 2012, 9:58 am
---------------------------------------------------------
File A.h:
#ifndef _A_h
#define _A_h
class A{
public:
A(int id);
private:
int _id;
B _b; // HERE I GET A COMPILATION ERROR: B does not name
a type
};
#endif
File A.cpp:
#include "A.h"
#include "B.h"
#include <cstdio>
A::A(int id): _id(id), _b(){
printf("hello\n the id is: %d\n", _id);
}
File B.h:
#ifndef _B_h
#define _B_h
class B{
public:
B();
};
#endif
File B.cpp:
#include "B.h"
#include <cstdio>
B::B(){
printf("this is hello from B\n");
}
I first compile the B class and then the A class, but then I get
the error message:
A.h:9: error: ‘B’ does not name a type
How do I fix this problem?
#Post#: 218--------------------------------------------------
Re: solve this problem...
By: ravusairam Date: November 27, 2012, 3:35 am
---------------------------------------------------------
I think if we change the order from
#include "A.h"
#include "B.h"
to
#include "B.h"
#include "A.h"
it will work because then the definition of B is available for
the object in A.
#Post#: 219--------------------------------------------------
Re: solve this problem...
By: kranthipls Date: November 27, 2012, 3:46 am
---------------------------------------------------------
I think ravu is correct........
#Post#: 221--------------------------------------------------
Re: solve this problem...
By: vsr Date: November 27, 2012, 4:42 am
---------------------------------------------------------
something else also needs to be done...
*****************************************************