In the below example I want to be able to access vector cList
in class B
in the function ShareData
. How do I do that?
I have written a sample code. It fails to compile (Error message: B has no constructors). Even if it did, does the line cObj = new B(*this);
introduce any circular dependency?
#include "stdafx.h"
#include <vector>
class B;
class A
{
public:
B* cObj;
std::vector<B*> cList;
A()
{
cObj = new B(*this);
}
};
class B
{
public:
B(A& aObj) : aObjLocal(aObj) {};
void ShareData(int result)
{
for (auto& iterator : aObjLocal.cList)
{
(*iterator).ShareData(result);
}
}
private:
A& aObjLocal;
};
void main()
{
A aMain;
B bMain(aMain);
bMain.ShareData(10);
}
Thanks in advance for sharing the knowledge.