My C++ Quiz

The ultimate place for testing what you have learned



Home | Start Quiz | List of questions  | Next Question | Login / Register

Question #58: What gets printed by this program?
58% on 877 times asked

#include <iostream>

struct Shape
{
  virtual void print()
  {
    std::cout << "SHAPE" << std::endl;
  }

  virtual ~Shape() {}
};

struct Box : public Shape
{
  virtual void print(int i)
  {
    std::cout << "BOX" << std::endl;
  }
};

int main(int argc, char** argv) 
{ 
  Shape* s = new Box;

  s->print();

  delete s;

  return 0; 
}

SHAPE
BOX
undefined
code is ill-formed
unspecified
© 2007-2010, My C++ Quiz, All rights reserved.
Can you find a bug in the quiz? Can you think of a new question that would be cool to add to this site? Email us and we will take action:
email us
Other Quizes | Contributors