Question:

What gets printed by this program?

#include <iostream>

struct Shape
{
  virtual Shape* duplicate()
  {
    std::cout << "SHAPE" << std::endl;
    return new Shape;
  }
  virtual ~Shape() {}
};

struct Box : public Shape
{
  virtual Box* duplicate()
  {
    std::cout << "BOX" << std::endl;
    return new Box;
  }
};

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

  Shape* s2 = s1->duplicate();

  delete s1;
  delete s2;
  return 0; 
}

Answers:


Keywords:

© 2017 QuizBucket.org