Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheritance problem 1

Status
Not open for further replies.

abp

Programmer
Sep 14, 2000
134
FR
Hi

I have a class defined like this

class CATDnbDocs {

public:

virtual void doload() = 0;
virtual void dodump() = 0;
...
};

I derive from this class and implement the above pure
virutal functions here:

class CATPartDocs : public CATDnbDocs {

public:

int doload();
int doload(CATDocument* doc);
...
};

I think what i am doing is just overriding the virtual function in the derived class. I am providing an implementation in the class's source file (CATPartDocs.cpp).
But when i try to compile this I am getting the following error.

D:\users\anand\projects\V5ServerWS\.\CATDocsApp\ProtectedInterfaces\CATPartDocs.h(28) : error C2555: 'CATPartDocs::doload' : overriding virtual function differs from 'CATDnbDocs::doload' only by return type or calling convention.

D:\users\anand\projects\V5ServerWS\.\CATDocsApp\ProtectedInterfaces\CATPartDocs.h(30) : error C2555: 'CATPartDocs::dodump' : overriding virtual function differs from 'CATDnbDocs::dodump' only by return type or calling convention.

I cant understand what mistake I am making in the definitions. Could anyone point out the error ?

I am using VC 6 c++ compiler on an NT4 workstation, to
give the specifics. :)

Thanks

Anand



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mail me at abpillai@excite.com if you want additional help. I dont promise that I can solve your problem, but I will try my best.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Look, the first one returns void, but the secodn one returns int. If they have identically the same parameters, it is not allowed in C++. Both must return the same, if you want to say you're overriding. John Fill
1c.bmp


ivfmd@mail.md
 
From Straustrup's book:

1) types of arguments in virtual functions in derived class must not differ in based!
2) return type may differ in virtual function from based to derived but only so:

class A
{
public:
A();

virtual A* clone() { return new A(); }
};

class B : public A
{
public:
B();

virtual B* clone() { return new B(); }
};
 
Thanks John, i changed the argument of the
derived function(s) and it worked.

Anand ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mail me at abpillai@excite.com if you want additional help. I dont promise that I can solve your problem, but I will try my best.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top