By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

Is this a bug in g++ or MSDEV?

P: n/a
#include <string>
#include <iostream>

template <typename T>
class Base
{
public:
Base(){
};
~Base(){
};

void talk(){
std::cout << " this is base talk" << std::endl;
};

void talk(bool flag){
std::cout << " this is base talk with flag" << std::endl;
};
void sing(){
std::cout << " this is base sing" << std::endl;
};

};
template <typename T>
class Derived:public Base<T>
{
public:
Derived():Base<T>()
{

};
~Derived()
{
};
};
template <>
class Derived<int>:public Base<int>
{
public:
Derived():Base<int>()
{
talk(); // <--------------- Location A;
talk(false); // <--------------- Location B;
sing(); // <--------------- Location C;
};
~Derived()
{
};
void talk(){
std::cout << " this is derived talk" << std::endl;
};
};
int main(void)
{
Derived<int> m;
m.talk();
return 0;
}

when i compile it with g++, i get the following error:

/*
* mytest.cpp: In constructor `Derived<int>::Derived()':
* mytest.cpp:43: no matching function for call to
`Derived<int>::talk(bool)'
* mytest.cpp:49: candidates are: void Derived<int>::talk()
*/

I just wondering why in location C, the method sing() can be called
while talk(false) can not be called since both are in the base class.

when i compile it with MS VStudio. i get similar error:

Compiling...
mytest.cpp
D:\code\c++\TestGcc\mytest.cpp(43) : error C2660: 'talk' : function does
not take 1 parameters
Error executing cl.exe.

TestGcc.exe - 1 error(s), 0 warning(s)
is this a bug of implementation in compiler?

Jul 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
jesse wrote:

Compiling...
mytest.cpp
D:\code\c++\TestGcc\mytest.cpp(43) : error C2660: 'talk' : function does
not take 1 parameters
Error executing cl.exe.

TestGcc.exe - 1 error(s), 0 warning(s)
is this a bug of implementation in compiler?


Neither your definition of talk() in Derived has hidden the
definitions in Base.

Jul 19 '05 #2

P: n/a
I don't think so, i only overwrite the : void talk();
however, i didn't overwrite: void talk(bool flag)
their signatures are different.

lilburne wrote:
jesse wrote:

Compiling...
mytest.cpp
D:\code\c++\TestGcc\mytest.cpp(43) : error C2660: 'talk' : function
does not take 1 parameters
Error executing cl.exe.

TestGcc.exe - 1 error(s), 0 warning(s)
is this a bug of implementation in compiler?


Neither your definition of talk() in Derived has hidden the definitions
in Base.


Jul 19 '05 #3

P: n/a
jesse wrote:
I don't think so, i only overwrite the : void talk();
however, i didn't overwrite: void talk(bool flag)
their signatures are different.


The signatures make no difference. Once you declare a function called
'talk' in the derived class, it hides all 'talk' functions from the base
class regardless of their signatures. You can "unhide" them with a
using-declaration.

--
Best regards,
Andrey Tarasevich

Jul 19 '05 #4

P: n/a
Why Compiler design this this way? i don't see any pitfall or particular
reason?

at least, in java, it seems no hiding existing.

BTW, how to "unhide" them with a using-declaration.
what is syntax?

regards!

jesse
Andrey Tarasevich wrote:
jesse wrote:
I don't think so, i only overwrite the : void talk();
however, i didn't overwrite: void talk(bool flag)
their signatures are different.

The signatures make no difference. Once you declare a function called
'talk' in the derived class, it hides all 'talk' functions from the base
class regardless of their signatures. You can "unhide" them with a
using-declaration.


Jul 19 '05 #5

P: n/a


jesse wrote:
Why Compiler design this this way? i don't see any pitfall or particular
reason?

at least, in java, it seems no hiding existing.

BTW, how to "unhide" them with a using-declaration.
what is syntax?
never mind, it is Base<T>::talk(false);

regards!

jesse
Andrey Tarasevich wrote:
jesse wrote:
I don't think so, i only overwrite the : void talk();
however, i didn't overwrite: void talk(bool flag)
their signatures are different.


The signatures make no difference. Once you declare a function called
'talk' in the derived class, it hides all 'talk' functions from the base
class regardless of their signatures. You can "unhide" them with a
using-declaration.


Jul 19 '05 #6

P: n/a
jesse wrote:
Why Compiler design this this way? i don't see any pitfall or particular
reason?

at least, in java, it seems no hiding existing.

BTW, how to "unhide" them with a using-declaration.
what is syntax?


If you override an overloaded member function all other overloaded ones
get hidden in the derived class context. It is intended to avoid some
problems with unexpected calls of member functions the author of the
overridden version might not be aware of. There are some issues with
implicit type promotion in C++ that may lead to unpredictable results in
some situations.

In your case you must explicitly scope the base member function:

Base::talk(false);

or "unhide" it when overriding like:

/...
using Base<int>::talk;
void talk(){ /* ... */ }
/...

Regards,
Janusz

Jul 19 '05 #7

P: n/a
Wed, 05 Nov 2003 16:37:24 -0800 , jesse <je*****@yahoo.com> :
#include <string>
#include <iostream>

template <typename T>
class Base
{
public:
Base(){
};
~Base(){
};

void talk(){
std::cout << " this is base talk" << std::endl;
};

void talk(bool flag){
std::cout << " this is base talk with flag" << std::endl;
};
void sing(){
std::cout << " this is base sing" << std::endl;
};

};
template <typename T>
class Derived:public Base<T>
{
public:
Derived():Base<T>()
{

};
~Derived()
{
};
};
template <>
class Derived<int>:public Base<int>
{
public:
Derived():Base<int>()
{
talk(); // <--------------- Location A;
talk(false); // <--------------- Location B;
sing(); // <--------------- Location C;
};
~Derived()
{
};
void talk(){
std::cout << " this is derived talk" << std::endl;
};
};
int main(void)
{
Derived<int> m;
m.talk();
return 0;
}

when i compile it with g++, i get the following error:

/*
* mytest.cpp: In constructor `Derived<int>::Derived()':
* mytest.cpp:43: no matching function for call to
`Derived<int>::talk(bool)'
* mytest.cpp:49: candidates are: void Derived<int>::talk()
*/

I just wondering why in location C, the method sing() can be called
while talk(false) can not be called since both are in the base class.

when i compile it with MS VStudio. i get similar error:

Compiling...
mytest.cpp
D:\code\c++\TestGcc\mytest.cpp(43) : error C2660: 'talk' : function does
not take 1 parameters
Error executing cl.exe.

TestGcc.exe - 1 error(s), 0 warning(s)
is this a bug of implementation in compiler?

it's rule.
see C++ 98 part: 10.2: Member name lookup.

for your source code, explicit using Base<int>::talk(false); or
explicit using:
using Base<int>::talk;

that's will resolve your problem

[comp.lang.c++]
[comp.lang.c++.moderated]
DarkSpy, A C++ Mad Dog. :-)
Jul 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.