0
C++ Polymorphism
class A { public: A(){}; virtual void L() const = 0; } class B : public A { public: B() : A() { }; void L() const override { // Do Stuff; } void Other() { // Other Stuff; } } A* U = new B; A->L(); // This Call Works A->Other(); // This Call is not working can anyone explain. Please
2 Answers
0
Could I ask you why are you calling Other() from A class(parent)? A class doesn't have Other method in this code.
0
For Example
class A
{
public:
A(){};
virtual void L() const = 0;
virtual void Other() = 0;
}
class B : public A
{
public:
B() : A() { };
void L() const override { // Do Stuff; }
void Other() override { // Other Stuff; }
}
class C : public A
{
public:
// Now, Here I don't Need to Implement "Other()" But I do need L()
// So to avoid implementing Other() in this class I remove it from Abstract
// class and implement it in Class B alone since It Make sense inside class B
// And I Do Need Class A functionality here (Kind of "Not all of them")
}