C++ multiple inheritance problem
I want to use a class composed of all pure virtual functions as like 'interface' in java. but instantiating a new derived class as interface class is not allowed.
like following code:
class ISampleProvider{
virtual CObject getSample() = 0;
}
class BaseClass{
method A...
method B...
}
class A : public BaseClass, public ISampleProvider{
method A...
mehtod B...
// implementation for ISampleProvider
CObject getSample(){
return m_thisSample;
}
}
void main(){
//A *a = new A ; // this expression does not make problems.
BaseClass *a = new A;
ISampleProvider *sample =
dynamic_cast<ISampleProvider*>(a);
if(sample)
sample->getSample(); // error occurs
}
}
error occurs just like:
" The value of ESP was not properly saved accross a function call. his is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."
Like this, main() can get the sample object if the class implemented ISampleViewable interface, regardless of the type of the class.
It's a powerful expression of Java, but I think this is not supported in C++ 'cause the typing policy or 'virtual' mechanism of C++
cannot support it.
I wanna know whether this expression is not allowed originally in C++ or some another way exists...
thanx