|
template <class TYPE> class CTemplate
{
public:
typedef void (TYPE::*CBFN)();
CTemplate()
{
m_pObject = NULL;
m_fnOncallback = NULL;
}
public:
void SetObject(TYPE* pObject)
{
m_pObject = pObject;
}
void AddOncallback(CBFN pfn)
{
m_fnOncallback = pfn;
}
private:
TYPE *m_pObject;
CBFN m_fnOncallback;
};
class CTest
{
CTest();
~CTest(){};
void OnCallback();
private:
CTemplate<CTest> m_temp;
};
CTest::CTest()
{
m_temp.SetObject(this);
m_temp.AddOncallback(OnCallback);
}
void CTest::OnCallback()
{
}
在vs.net 2003编译通过
gcc编译不过去,错误如下:
make all-recursive
make[1]: Entering directory `/root/code/test4'
Making all in src
make[2]: Entering directory `/root/code/test4/src'
c++ -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c test3.cpp
test3.cpp:59: warning: all member functions in class `CTest' are private
test3.cpp: In constructor `CTest::CTest()':
test3.cpp:70: error: no matching function for call to `CTemplate<CTest>::AddOncallback(<unknown type>)'
test3.cpp:47: error: candidates are: void CTemplate<TYPE>::AddOncallback(void (TYPE::*)()) [with TYPE = CTest]
make[2]: *** [test3.o] 错误 1
make[2]: Leaving directory `/root/code/test4/src'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/root/code/test4'
make: *** [all-recursive-am] 错误 2
谁能给我解释一下?谢拉!! |
|