-1

I have declared a virtual method in super class. I want to call that method using the super class pointer which is pointing to the sub class object. For example:

class A            { virtual void foo(); }
class B : public A { virtual void foo(); }

A *b = new B();
Sujeeth Damodharan
  • 477
  • 2
  • 7
  • 16
  • maybe this helps you: http://stackoverflow.com/questions/672373/can-i-call-a-base-classs-virtual-function-if-im-overriding-it or google is your friend: http://google.com/search?hl=en&num=50&safe=off&q=c%2B%2B+call+virtual+super+function – antibus Jun 29 '13 at 14:57
  • @Saksham yes he does, to call the base class method. – Luchian Grigore Jun 29 '13 at 15:16

1 Answers1

1

The approach is good, but A::foo() is private - to call it, it would need to be public.

You're also missing the implementations and the trailing ; after the class definition.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625