I am trying to remove the need to #include stl elements in my header (a requirement for a project I work on). I wrote a "wrapper" for std::vector called "MyVector". I declare a pointer to a MyVector as a member of MyClass. Then when I try to use this in MyDerivedClass, I get
"invalid use of incomplete type 'struct MyVector'
forward declaration of 'struct MyVector'
Can anyone see what I have done wrong below?
Test.cxx
#include "MyDerivedClass.h"
int main(int, char *[])
{
MyDerivedClass a;
a.DoSomething();
return 0;
}
MyClass.h
#ifndef myclass_h
#define myclass_h
struct MyVector; //forward declaration of 'struct MyVector'
class MyClass
{
public:
MyClass();
~MyClass();
MyVector* vecPtr;
};
#endif
MyClass.cxx
#include "MyClass.h"
#include <vector>
struct MyVector
{
std::vector<double> v;
};
MyClass::MyClass()
{
this->vecPtr = new MyVector;
}
MyClass::~MyClass()
{
delete this->vecPtr;
}
MyDerivedClass.h
#ifndef myderivedclass_h
#define myderivedclass_h
#include "MyClass.h"
class MyDerivedClass : MyClass
{
public:
void DoSomething();
};
#endif
MyDerivedClass.cxx
#include "MyDerivedClass.h"
void MyDerivedClass::DoSomething()
{
this->vecPtr->v.push_back(1); //"invalid use of incomplete type 'struct MyVector'
}
Thanks,
David