My C++ Quiz

The ultimate place for testing what you have learned



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

Question #47: Which, if any, of the member function definitions below are ill-formed?
53% on 887 times asked

#include <iostream>

int g_x = 44; 

struct Foo 
{ 
  int m_x; 

  static int s_x; 

  Foo(int x) : m_x(x) {} 

  int a(int x = g_x) 
  { 
    return x + 1; 
  } 

  int b(int x = m_x) 
  { 
    return x + 1; 
  } 

  int c(int x = s_x) 
  { 
    return x + 1; 
  } 
}; 

int Foo::s_x = 22; 

int main(int argc, char** argv) 
{ 
  Foo f(6); 

  std::cout << f.a() << std::endl; 
  std::cout << f.b() << std::endl; 
  std::cout << f.c() << std::endl; 

  return 0; 
}

a
b
c
a and b
none
© 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