Tak for svaret.
Her er den løsning jeg fik:
main.cpp:
#include <iostream>
#include "A.h"
int main(int argc, char *argv[])
{
A obj;
obj.setT("Tst");
obj.Test();
obj.setT("Test");
obj.Test();
B b=obj.getB();
obj.setT("Test2");
b.test();
system("PAUSE");
return EXIT_SUCCESS;
}
A.h
#ifndef A_H
#define A_H
#include "B.h"
class A{
private:
B mB;
char* T;
public:
void setT(char* aT);
void Test();
void print();
B getB();
};
#endif
A.cpp
#ifndef A_CPP
#define A_CPP
#include "A.h"
#include <iostream>
B A::getB(){
return mB;
}
void A::setT(char* aT){
T=aT;
}
void A::Test(){
mB.setOwner(this);
}
void A::print(){
std::cout<<T<<std::endl;
}
#endif
B.h
#ifndef B_H
#define B_H
class A;
class B{
private:
A* fOwner;
public:
void setOwner(A* aOwner);
void test();
};
#endif
B.cpp
#ifndef B_CPP
#define B_CPP
#include "A.h"
#include "B.h"
void B::setOwner(A* aOwner){
fOwner=aOwner;
fOwner->print();
}
void B::test(){
fOwner->print();
};
#endif B_CPP