Question:

What gets printed by this program?

#include <iostream>

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

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

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

struct GeoDisc : public Box, public Sphere
{
};

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

  s->print();

  delete s;

  return 0;
}

Answers:


Keywords:

© 2017 QuizBucket.org