Z
Zeng Dinghao
I encouter this problem.
here are the sample files:
//--------------- File: Bar.h ------------------------------
class Bar : public BarBase {
public:
void BarFunc(); // there is no BarFunc in Barbase
};
//----------------------------------------------------------
//--------------- File: Bar.cpp ----------------------------
void Bar::BarFunc() {
}
//----------------------------------------------------------
//----------------File: Client.h ---------------------------
class Bar; // ! Forward Declaration !
// I don't include "Bar.h", since
// I want to decrease the dependency
void Foo(BarBase* pBarBase); // defined in other .cpp file
class Client {
public:
// ... some other declaration
template<class>
void TemplFunc(T& data) {
// do sth. about data
Foo(m_pBar);
}
protected:
Bar* m_pBar;
};
//-----------------------------------------------------------
//----------------File: Client.cpp---------------------------
#include "Bar.h" // I include it here
Client::Client() {
m_pBar = new Bar();
m_pBar->BarFunc();
}
//-----------------------------------------------------------
The compiler complained that
can not convert type "Bar*" to type "BarBase*"
when calling "void Foo(BarBase* pBarBase)" in "TemplFunc"
How can I get through without including "Bar.h" in "Client.h" ?
I insist this because there are many files need to include "Client.h".
In other word, can the Forward Declaration contain the infomation of
inheritance ?
here are the sample files:
//--------------- File: Bar.h ------------------------------
class Bar : public BarBase {
public:
void BarFunc(); // there is no BarFunc in Barbase
};
//----------------------------------------------------------
//--------------- File: Bar.cpp ----------------------------
void Bar::BarFunc() {
}
//----------------------------------------------------------
//----------------File: Client.h ---------------------------
class Bar; // ! Forward Declaration !
// I don't include "Bar.h", since
// I want to decrease the dependency
void Foo(BarBase* pBarBase); // defined in other .cpp file
class Client {
public:
// ... some other declaration
template<class>
void TemplFunc(T& data) {
// do sth. about data
Foo(m_pBar);
}
protected:
Bar* m_pBar;
};
//-----------------------------------------------------------
//----------------File: Client.cpp---------------------------
#include "Bar.h" // I include it here
Client::Client() {
m_pBar = new Bar();
m_pBar->BarFunc();
}
//-----------------------------------------------------------
The compiler complained that
can not convert type "Bar*" to type "BarBase*"
when calling "void Foo(BarBase* pBarBase)" in "TemplFunc"
How can I get through without including "Bar.h" in "Client.h" ?
I insist this because there are many files need to include "Client.h".
In other word, can the Forward Declaration contain the infomation of
inheritance ?