Alex Rivera | Logout

why a const object of an empty class cant be created

Asked 2011-03-17T06:55:53.670
11
#include <iostream>

class A {
   public:
      void foo() const {
          std::cout << "const version of foo" << std::endl;
      }
      void foo() {
          std::cout << "none const version of foo" << std::endl;
      }
};

int main()
{
  A a;
  const A ac;
  a.foo();
  ac.foo();
}

The above code can't be compiled, could anyone of you tell me why?

Edit
Report

1 Answer

13

You need to initialize it. This is a known problem with the spec.

answered 2011-03-17T06:57:15.883

Your Answer