C++ Topics and Explanations
C++ multiple inheritance problem

[ Follow Ups ] [ Post Follow Up ] [ C++ Topics and Explanations ]

Posted by jinyoung jang on February 07, 202 at 21:48:10:

I want to use a class composed of all pure virtual functions as like 'interface' in java, but instantiating the interface class is not allowed in C++. like following code.

in C++,

class ISampleProvider{
virtual CObject getSample() = 0;
}

class A : public CObject, public ISampleProvider{
method A...
mehtod B...

// implementation for ISampleProvider
CObject getSample(){
return m_thisSample;
}
}

void main(){
A *a = new A;
ISampleProvider *sample =
dynamic_cast(a);

if(sample)
sample.getSample(); // error occurs
}

It's so powerful expression in java, but C++ does not support it. I think.

I wanna know that this is essential feature of C++ or another exprssion or technique exists.

thank you.




Follow Ups:


Post a Follow Up:

Name:
E-Mail:

Subject:

Comments:


[ Follow Ups ] [ Post Follow Up ] [ C++ Topics and Explanations ]