Can I call a base class's virtual function if I'm overriding it?

The C++ syntax is like this: class Bar : public Foo { // ... void printStuff() { Foo::printStuff(); // calls base class' function } }.

– David Relihan Feb 2 at 15:01 3 @David: No, it's perfectly normal to do this, though it might depend on your actual class if it is actually useful. Only call the base class method if does something you want to happen ;). – sth Feb 2 at 15:13.

Yes, class Bar : public Foo { ... void printStuff() { Foo::printStuff(); } }; It is the same as super in Java, except it allows calling implementations from different bases when you have multiple inheritance. Class Foo { public: virtual void foo() { ... } }; class Baz { public: virtual void foo() { ... } }; class Bar : public Foo, public Baz { public: virtual void foo() { // Choose one, or even call both if you need to. Foo::foo(); Baz::foo(); } }.

Sometimes you need to call the base class' implementation, when you aren't in the derived function...It still works: struct Base { virtual int Foo() { return -1; } }; struct Derived : public Base { virtual int Foo() { return -2; } }; int _tmain(int argc, _TCHAR* argv) { Base *x = new Derived; ASSERT(-2 == x->Foo()); //syntax is trippy but it works ASSERT(-1 == x->Base::Foo()); return 0; }.

Just in case you do this for a lot of functions in your class: class Foo { public: virtual void f1() { // ... } virtual void f2() { // ... } //... }; class Bar : public Foo { private: typedef Foo super; public: void f1() { super::f1(); } }; This might save a bit of writing if you want to rename Foo.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions