On Sat, 2007-11-24 at 13:25 +0000, sowmya wrote:
> Hello,
> I wanted to know if calling a virtual function from another
> virtual function is valid or not.
Yes, you can.
> I was working on an assignmnet where
> the functions are pure in the base class and have definitions in the
> derived class.
> I used g++ to compile the code and I was getting a runtime error
> saying "pure virtual function called. aborted".
> The program executes fine when the declaration is removed in the
> base class.Can anyone please tell me the reason?
>
> I have included the brief structure of the code
> class base
> {
> public:
> virtual void abc() ;
pure virtual: virtual void abc() = 0;
> virtual void efg();
> };
>
> class derived: public base
> {
> public:
> virtual void abc(){ }
> virtual void efg(){ ...
> abc();
> ...
> }
> };
>
> Regards,
> Sowmya
>
I don't see there is a problem here. I have wrote a test
program to verify it:
#include <iostream>
using namespace std;
class Base
{
public:
virtual void procedure() = 0;
virtual void signature() = 0;
};
class Derived : public Base
{
public:
virtual void procedure()
{
cout << "procedure called" << endl;
}
virtual void signature()
{
this->procedure();
cout << "signature called" << endl;
}
};
int main()
{
Derived subclass;
subclass.signature();
return 0;
}
>
>
>
>