[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: inheritance scope
From: |
Maurizio Loreti |
Subject: |
Re: inheritance scope |
Date: |
26 Nov 2004 21:12:36 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
Gav <gav@cs.york.ac.uk> writes:
> hi,
>
> could someone tell me why this program (which results in a compilation
> error) shouldn't compile (i.e. is it a gcc thing or is it a strict part of
> c++), and how i can make it compile without having to put C:: before foo()
> in main()?
>
> essentially i want the foo() from A to be overloaded as i would expect if it
> was actually inserted into C.
>
> thanks, gav
>
> #include <iostream>
> class A
> { public: void foo() { std::cerr << "A::foo(int)" << std::endl; }
> };
> class C : public A
> { public: void foo(int) { std::cerr << "C::foo(int)" << std::endl; }
> } c;
> int main()
> { c.foo();
> return 0;
> }
>
ah, since we are here... class from which you derive, like A, should
have a virtual destructor declared. and make A:foo() virtual, too.
good programming habits should be used also in toy snippets (from
kernighan & pike, iirc :-)
--
Maurizio Loreti http://www.pd.infn.it/~loreti/mlo.html
Dept. of Physics, Univ. of Padova, Italy ROT13: ybergv@cq.vasa.vg