C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Call of overloaded derived method problem

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Lagarde s?bastien
Guest





PostPosted: Wed Jan 28, 2004 5:17 pm    Post subject: Call of overloaded derived method problem Reply with quote



Hello,

I have the following code

struct Toto
{
void Add(int x){}
};

struct Titi : public Toto
{
void Add(int x, int y){}
};

int main ()
{
Titi titi;
titi.Add(1);
}

and i get the following error msg :
main.cpp(19): error C2660: 'Titi::Add' : function does not take 1 parameters

if i change the code "titi.Add(1);" to "titi.Toto::Add(1);"
There is no more problem.

Is this a specific C++ behavior ? or my compiler (msvc7) ?
Is there a good way to write "titi.Add(1)".

I know i can wrap "Add" in Titi class and call Add Parent but
if i can avoid this...

Thanks.
Back to top
Karl Heinz Buchegger
Guest





PostPosted: Wed Jan 28, 2004 5:24 pm    Post subject: Re: Call of overloaded derived method problem Reply with quote



Lagarde s?bastien wrote:
Quote:

Hello,

I have the following code

struct Toto
{
void Add(int x){}
};

struct Titi : public Toto
{
void Add(int x, int y){}
};

int main ()
{
Titi titi;
titi.Add(1);
}

and i get the following error msg :
main.cpp(19): error C2660: 'Titi::Add' : function does not take 1 parameters

if i change the code "titi.Add(1);" to "titi.Toto::Add(1);"
There is no more problem.

Is this a specific C++ behavior ?

Yes.

Quote:
or my compiler (msvc7) ?

No. Your compiler is correct.
The Add function in Titi hides the Add function in Toto

Quote:
Is there a good way to write "titi.Add(1)".

struct Titi : public Toto
{
using Toto::Add;

void Add( int x, int y );
};

Quote:

I know i can wrap "Add" in Titi class and call Add Parent but
if i can avoid this...

Thanks.


--
Karl Heinz Buchegger
[email]kbuchegg (AT) gascad (DOT) at[/email]

Back to top
Sreenivas M
Guest





PostPosted: Thu Jan 29, 2004 4:01 am    Post subject: Re: Call of overloaded derived method problem Reply with quote




"Lagarde s?bastien" <slagarde (AT) e-neko (DOT) com> wrote

Quote:
Hello,

I have the following code

struct Toto
{
void Add(int x){}
};

struct Titi : public Toto
{
void Add(int x, int y){}
};

int main ()
{
Titi titi;
titi.Add(1);
}

and i get the following error msg :
main.cpp(19): error C2660: 'Titi::Add' : function does not take 1
parameters

if i change the code "titi.Add(1);" to "titi.Toto::Add(1);"
There is no more problem.

Is this a specific C++ behavior ? or my compiler (msvc7) ?
Is there a good way to write "titi.Add(1)".

I know i can wrap "Add" in Titi class and call Add Parent but
if i can avoid this...

Thanks.

Hello,

Overloading works only in the same scope..
The methods are not overloded if they are in different scope.
The compiler would issue an error, as it cannot find the other Add method.

Thanx.
sreeni



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.