My C++ Quiz

The ultimate place for testing what you have learned



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

Question #71: What gets printed?
50% on 868 times asked

#include <iostream>

int foo(int i)
{
  return 2;
}

double foo(double d)
{
  return 4.0;
}

struct Computer
{
  int foo(int i)
  {
    return 8; 
  }
};

struct Gateway : public Computer
{
  double foo(double d)
  {
    return 16.0; 
  }
};

int main(int argc, char** argv)
{
  Gateway g;

  std::cout << foo(1) + foo(1.0) + g.foo(1) + g.foo(1.0) << std::endl;

  return 0;
}

20
30
38
40
The code is ill-formed
© 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