 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Lagarde s?bastien Guest
|
Posted: Wed Jan 28, 2004 5:17 pm Post subject: Call of overloaded derived method problem |
|
|
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
|
Posted: Wed Jan 28, 2004 5:24 pm Post subject: Re: Call of overloaded derived method problem |
|
|
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
|
Posted: Thu Jan 29, 2004 4:01 am Post subject: Re: Call of overloaded derived method problem |
|
|
"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 |
|
 |
|
|
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
|
|