473,396 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is this a bug in g++ or MSDEV?

#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
7 2285
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
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
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
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


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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John Doe | last post by:
#include "project.h" class ThatDoesProcessing; typedef int (ThatDoesProcessing::*PFUNC)(int); class ThatDoesProcessing { public:
1
by: Lars Schouw | last post by:
Does any one know what msdev.exe was replaced by since Visual Studio 6.0? Lars
2
by: oguz | last post by:
I am using Visual C++ 6.0 msdev.exe from the command line to build all the projects in a workspace ( .dsw ). The command syntax that I am using is: msdev all.dsw /make "ALL" /REBUILD /OUT ...
1
by: Shawn Campbell | last post by:
Here's my situation! I'm automating the building of Visual Studio projects/workspaces running MSDEV from the command line like: MSDEV.EXE foobar.dsw /MAKE "Config1 - Win32 Release" /USEENV ...
0
by: Jean Stax | last post by:
Hi! I have a MyKey.snk file, which I genereated in command line. I put this file in the workspace / source files directory. My C# code reference it as AssemblyKeyFileAttribute("MyKey.snk"). The...
6
by: WTH | last post by:
....is there a way to get the command line build tools to do this? Anyone build web services clients via the command line (not using make files)? Thanks, WTH
3
by: Bit byte | last post by:
Anyone using CVS with MSDEV? How can I use CVS (my current repository) with VS2003? Did a google search but nothing definitive. Some docu or pointers will be very helpful
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.