S
Soren Holstebroe
Hi lang.c++,
Having programmed in Java for quite a while now I was a bit surprised when
the following c++ construction didn't compile:
--------------------
#include <iostream>
class A {
public:
void f() {
std::cout << "Foo" << std::endl;
}
};
class B : public A {
public:
void f(int i) {
std::cout << "Bar = " << i << std::endl;
}
};
int main() {
B b;
b.f();
b.f(5);
return 0;
}
-------------------
bash-2.05b$ g++ --version
g++ (GCC) 3.3.5 (Gentoo Linux 3.3.5-r1, ssp-3.3.2-3, pie-8.7.7.1)
bash-2.05b$ g++ polym.cc
polym.cc: In function `int main()':
polym.cc:18: error: no matching function for call to `B::f()'
polym.cc:11: error: candidates are: virtual void B::f(int)
-------------------
Can someone enlighten me why method overloading is not possible in this
case ?
--
Søren Holstebroe
Scientific Programmer
e: (e-mail address removed)
w: http://www.wjc.ku.dk
p: +45 353 27819
Having programmed in Java for quite a while now I was a bit surprised when
the following c++ construction didn't compile:
--------------------
#include <iostream>
class A {
public:
void f() {
std::cout << "Foo" << std::endl;
}
};
class B : public A {
public:
void f(int i) {
std::cout << "Bar = " << i << std::endl;
}
};
int main() {
B b;
b.f();
b.f(5);
return 0;
}
-------------------
bash-2.05b$ g++ --version
g++ (GCC) 3.3.5 (Gentoo Linux 3.3.5-r1, ssp-3.3.2-3, pie-8.7.7.1)
bash-2.05b$ g++ polym.cc
polym.cc: In function `int main()':
polym.cc:18: error: no matching function for call to `B::f()'
polym.cc:11: error: candidates are: virtual void B::f(int)
-------------------
Can someone enlighten me why method overloading is not possible in this
case ?
--
Søren Holstebroe
Scientific Programmer
e: (e-mail address removed)
w: http://www.wjc.ku.dk
p: +45 353 27819