Hi,
Why can't I do the following:
As I get the compile error:Code:#include <stdio.h> #include <stdlib.h> class A { public: A(); A(char *spam); }; A::A() { fprintf(stderr, "spam is good\n"); } A::A(char *spam) { fprintf(stderr, "spam is %s\n", spam); } class B : public A { }; int main() { // works A *a_name; a_name = new A("awesome"); // doesn't work - how do I make it work? B *a_name; a_name = new B("great"); return 0; }
Thx.Code:navi:~/projects/0_sandbox/cpp> make test_inheriance g++ test_inheriance.cpp -Wall -O -g -I. -o test_inheriance test_inheriance.cpp: In function ‘int main()’: test_inheriance.cpp:31: error: conflicting declaration ‘B* a_name’ test_inheriance.cpp:27: error: ‘a_name’ has a previous declaration as ‘A* a_name’ test_inheriance.cpp:32: error: no matching function for call to ‘B::B(const char [6])’ test_inheriance.cpp:20: note: candidates are: B::B() test_inheriance.cpp:20: note: B::B(const B&) make: *** [test_inheriance] Error 1



LinkBack URL
About LinkBacks



