Entry 968
Methods virtuality example
Submitted by Raphaƫl Gaudy
on Aug. 26, 2008 at 11:06 p.m.
Language: C++. Code size: 465 bytes.
#include <iostream> using namespace std; class A { public: virtual char m() { //Uncomment "virtual" and see... return 'A'; }; }; class B : public A { public: /*virtual*/ char m() { return 'B'; } }; int main (int argc, char * const argv[]) { A* a = new B; cout << "a (A*, B) : method of class " << a->m() << endl; B* b = new B; cout << "b (B*, B) : method of class " << b->m() << endl; delete a; delete b; return 0; }
This snippet took 0.00 seconds to highlight.
Back to the Entry List or Home.