So I am creating a project that involves having vectors nested inside one another, but the structure won't compile. I think this is a case of circular dependency, but all of the fixes I've seen seem to only apply to code involving header files.
#include<iostream>
#include<vector>
using namespace std;
class A
{
virtual ~A();
};
class B : public A
{
vector<A*> Avector;
void addC(C* Cin){Avector.push_back(Cin);};
~B();
};
class C : public A
{
vector<A*> Avector;
void addB(B* Bin){Avector.push_back(Bin);};
~C();
};
int main()
{
}
I've tried forward declaring with
class C;
Class C : public A;
But none of it seems to work.
The error I get is:
\test\test\source.cpp(15): error C2061: syntax error : identifier 'C'
\test\test\source.cpp(15): error C2065: 'Cin' : undeclared identifier
Is this sort of code implementable?
Thanks for taking the time to read this.
Aucun commentaire:
Enregistrer un commentaire