H
Harald Finster
Hello,
sorry, this is probably a really dumb question, but I don't
understand the behavior of the g++ compiler at the moment.
The following snippet
-------- Test.cpp -----
#include <iostream>
class Base {
public:
void foo( int i ) {
std::cerr << "foo(int)" << std::endl;
}
};
class Derived : public Base {
public:
void foo( const char * i ) {
std::cerr << "foo(char*)" << std::endl;
}
};
int main( int argc, char ** argv ) {
Derived d;
d.foo("Hello");
d.foo(123);
}
--------
results in the following error:
g++ Test.cpp
Test.cpp: In function ‘int main(int, char**)’:
Test.cpp:30: error: invalid conversion from ‘int’ to ‘const char*’
Test.cpp:30: error: initializing argument 1 of ‘void
Derived::foo(const char*)’
Seems, that the compiler does not take differing parameter types
of the member functions into account. My understanding was, that
member-functions are regarded as 'different' if the names and/or
parameter types differ. (Only the return type is ignored.)
I expected, that Derived inherits foo(int) from Base and
thus has the member functions:
foo(int)
foo(const char*)
Instead foo(const char*) seems to overwrite foo(int)
Am I wrong?
The same snipped works as expected (by me) with EVC for example.
Thanks for any feedback - I am really confused :~{
Kind regards
Harald
sorry, this is probably a really dumb question, but I don't
understand the behavior of the g++ compiler at the moment.
The following snippet
-------- Test.cpp -----
#include <iostream>
class Base {
public:
void foo( int i ) {
std::cerr << "foo(int)" << std::endl;
}
};
class Derived : public Base {
public:
void foo( const char * i ) {
std::cerr << "foo(char*)" << std::endl;
}
};
int main( int argc, char ** argv ) {
Derived d;
d.foo("Hello");
d.foo(123);
}
--------
results in the following error:
g++ Test.cpp
Test.cpp: In function ‘int main(int, char**)’:
Test.cpp:30: error: invalid conversion from ‘int’ to ‘const char*’
Test.cpp:30: error: initializing argument 1 of ‘void
Derived::foo(const char*)’
Seems, that the compiler does not take differing parameter types
of the member functions into account. My understanding was, that
member-functions are regarded as 'different' if the names and/or
parameter types differ. (Only the return type is ignored.)
I expected, that Derived inherits foo(int) from Base and
thus has the member functions:
foo(int)
foo(const char*)
Instead foo(const char*) seems to overwrite foo(int)
Am I wrong?
The same snipped works as expected (by me) with EVC for example.
Thanks for any feedback - I am really confused :~{
Kind regards
Harald