[Bug c++/34307] New: when data member name is same as parameter name, possible to omit parameter name in constructor without warning
myselfhimself at free dot fr
gcc-bugzilla@gcc.gnu.org
Sat Dec 1 04:06:00 GMT 2007
under Linux 2.6.20, KUbuntu Gutsy with gcc 4.1.3
compiling for use on linux
#if 0
//first here:
//g++ accepts to compile no parameter name is given anytime (not in the class
definition neither in the constructor implementation)
//the program runs ok though
#include <iostream>
using namespace std;
class Hop
{
public:
Hop(string);
void fct(string);
};
Hop::Hop(string)
{}
void Hop::fct(string)
{}
int main()
{
Hop a("txt");
return 0;
}
#endif
#if 1
//second: when using an option parameter for constructor
//if we use this parameter name again for member initialisation and it's the
same as a data member name
//this gives no compile pb
//+a crash when running
#include <iostream>
using namespace std;
class Hop
{
public:
Hop(string msg="no_msg");
void sayMsg();
string msg;
};
Hop::Hop(string):msg(msg)
{}
void Hop::sayMsg()
{
cout << "msg is:"<<msg<<"-done" <<endl;
}
int main()
{
Hop a("yo");
Hop b("");
a.sayMsg();
b.sayMsg();
return 0;
}
#endif
--
Summary: when data member name is same as parameter name,
possible to omit parameter name in constructor without
warning
Product: gcc
Version: 4.1.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: myselfhimself at free dot fr
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34307
More information about the Gcc-bugs
mailing list