well, as I mentioned, getting the interface from the baseclass is not possible, only A has this interface. The following works fine:
PHP Code:
#include <afx.h>
class ISampleProvider
{
public:
virtual CObject* getSample() = 0;
};
class BaseClass
{
public:
void Test();
};
class A : public BaseClass, public ISampleProvider
{
private:
CObject* m_thisSample;
public:
A()
{
m_thisSample = NULL;
}
virtual CObject* getSample()
{
return m_thisSample;
}
};
int main()
{
BaseClass *a = new A();
// you are casting the baseclass to ISampleProvider here
// though this happens to be ok, make sure it's no problem
// with the design, because BaseClass has no ISampleProvider
// interface. Only A has, so you might want to cast it to A
// first, then to ISampleProvider.
// EDIT: Right, cast it to A first, because Baseclass ( pointer a )
// has NO ISampleProvider Interface. So casting from Baseclass
// to ISampleProvider will result in errors.
ISampleProvider* sample = (ISampleProvider*)(A*)a;
printf("%p\n", sample->getSample() );
return 0;
}
// this prints out 0x00000000 as expected