[求教]父类方法调用子类对象和方法的问题
//LibraryBuileerPlugins.h
class CLibraryBuilderPlugins
{
public:
static bool ExtractPluginMetadata(DWORD nIndex, const CString& strPath);
private:
.......
};
//LibraryBuileerPlugins.cpp
bool CLibraryBuilderPlugins::ExtractPluginMetadata(DWORD nIndex, const CString& strPath)
{
.....
return LibraryBuilder.SubmitMetadata( nIndex, strSchemaURI, pInner ) != 0;
.....
else if ( hr == E_UNEXPECTED )
{
return LibraryBuilder.SubmitCorrupted( nIndex );
}
......
}
//LibraryBuilder.h
class CLibraryBuilder :
public CLibraryBuilderInternals
, public CLibraryBuilderPlugins
, public CThreadImpl
{
public:
CLibraryBuilder();
virtual ~CLibraryBuilder();
.....
bool SubmitCorrupted(DWORD nIndex);
bool RefreshMetadata(const CString& sPath);
..........
}
extern CLibraryBuilder LibraryBuilder;
问题是,父类CLibraryBuilderPlugins中的方法怎么可以引用子类的对象和方法?这个应该怎样理解呢?谢谢
[解决办法]
class s
{
b b1;
public:
void test(){
b1.foo();//这里为何不行????
}
};
class b:s{
public:
void foo(){}
}