[ create a new paste ] login | about

Link: http://codepad.org/bhLGPtml    [ raw code | output | fork ]

johannes - C++, pasted on Aug 29:
#include <iostream.h>

class Base
{
public:
   virtual ~Base() {}

   virtual void doSomething() const;
   virtual void doSomething(int x) const;
};

void Base::doSomething() const
{
   std::cout << "ping\n";
}

void Base::doSomething(int x) const
{
   std::cout << "pong\n";
}

class Derived : public Base
{
public:
   void doSomething() const;
   using Base::doSomething;

//   void doSomething(int x) const { Base::doSomething(x); }
};

void Derived::doSomething() const
{
   std::cout << "hello\n";
}

int main(int argc, char **argv)
{
   Base base;
   base.doSomething();             // ping
   base.doSomething(3);            // pong

   Derived derived;
   derived.doSomething();          // hello

   //derived.doSomething(3);         
   // error: no matching function for call to 'Derived::doSomething(int)'

   //derived.Base::doSomething(3);   // pong
   
   derived.doSomething(3);

   return 0;
}


Output:
1
2
3
4
ping
pong
hello
pong


Create a new paste based on this one


Comments: