How to create and use a class_b, inside a class_a

I have a class_a and class_b classes (with their .h and .c files)
I create an instance of class_a into my main,cpp.
After I use it in other cpp files using 'extern' .
Ok, how I can to create an instance of class_b inside class_a to use it in this way :

class_a.class_b.mymethod

Now I have a unreferenced error.
A piece of code will be appreciated.
Thanks
1
2
3
4
5
6
7
//A.h
//header guard

struct A{
   int i;
   ...
};

1
2
3
//A.cpp
#include "A.h"
...

1
2
3
4
5
6
7
8
//B.h
//header guard
#include "A.h"

struct B{
   A a;
   ...
};

1
2
3
//B.cpp
#include "B.h"
...

1
2
3
4
5
6
7
//main.cpp
#include "B.h"

int main(){
   B b;
   return b.a.i;
}


?
I have the same, except than I create the B b in main.cpp, later I use it using 'extern B b'.
Another more thing is that all is encapsulated into a QT DLL....
I'm going to think something more....


Thanks any way
you mean
1
2
3
4
5
6
7
//B.h
//header guard

struct B{
   int i;
   ...
};


1
2
3
//B.cpp
#include "B.h"
...


1
2
3
4
5
6
7
8
//A.h
//header guard
#include "B.h"

struct A{
   B b;
   ...
};


1
2
3
4
5
6
7
8
9
//A.cpp
#include "A.h"

extern A a;

void function(){
   a.b.i = 5;
}
...


1
2
3
4
5
6
7
8
//main.cpp
#include "A.h"

A a;

int main(){
   return 0;
}


?
Topic archived. No new replies allowed.