I wrote a simple smart point class but get in to trouble. The code BPtr mBptr;
in class A gose well while compiling, but failed in some other class with error: "error C2027: use of undefined type". So i have to include the B.h in header file rather then use forward declaration. I have no idea what`s going on. Dose anyone know about it?
I wrote these code like this:
//Pointer.h
template<class T>
class Pointer
{
public:
Pointer(T* pObject = nullptr);
...
private:
T* mPtr;
};
//Pointer.inl
template <class T>
Pointer<T>::Pointer(T* pObject)
{
mPtr = pObject;
if (mPtr)
{
mPtr->IncreRef();//IncreRef: function of class T
}
}
...
And i used in this way:
//A.h
#include "Pointer.h"
class B;
typedef Pointer<B> BPtr;
class A
{
public:
A();
~A();
private:
BPtr mBptr; //This might compiler error c2027
};
//A.cpp
#include "A.h"
#include "B.h"
A::A()
{
}
A::~A()
{
}