• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Overloaded functions

Hi,
I had posted a question some days back. I have refined my question a little    bit.
Please consider a class

class Base{
...
virtual fnSomefunction(int)=0;
}

class DER : public Base{
fnSomefunction(int);
fnSomefunction(int,int);
}

When I try to compile the above, I get an error.

\Test1.cpp(46) : error C2259: 'Base' : cannot instantiate abstract class due to following members:
Test1.cpp(4) : see declaration of 'Base'

Why cant I overload a pure virtual

function in a derived class?

Regards

Shayad.
0
shayad
Asked:
shayad
1 Solution
 
inprasCommented:
Hi shayad
U can overload the pure virtual function but a class with one or more pure virtual functions cannot be instantiated. Each pure virtual function must be overridden in a derived class before objects of the derived class can be instantiated.
So U cant vave an object defined of call Base. U can how ever create the objects of class DER
check this
#include<iostream.h>
class Base
{
public:
      virtual fnSomefunction(int)=0;
} ;

class DER : public Base
{
public:
      fnSomefunction(int)
      {
            return 1;
      }
      fnSomefunction(int,int)
      {
            return 2;
      }
} ;
void main(void)
{
      DER d;
      Base b;//This Gives an error
}
Regards

0
 
freshmeatCommented:
try this:

class Base{
....
virtual fnSomefunction(int)=0;
}

class DER : public Base{
 virtual fnSomefunction(int);
 virtual fnSomefunction(int,int);
}

BTW, in last question, i gave u the right answer, but the points r given to another guy who said some useless words...
:((((((((((

anyway, good luck to try my code
:)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now