문제

  1. In the code give below I got an error message that "there is no default constructor" .that's why I can't use uniform initializer.

  2. When I made a default constructor then I got an error regarding braces .

Kindly highlight the problem about this program and uniform initiallizer.

I am using VS 2012 and C++

class Circle {

    double radius;
  public:

    Circle(double r) { radius = r; }
    double circum() {return 2*radius*3.14159265;}
    Circle () {
    cout<<"ALI \n ";
    }
};

int main () {

  Circle baz {30.0};   // uniform init.

  Circle qux{};
  cout << "foo's circumference: " << baz.circum() << '\n';
  cout<<endl;
  return 0;
}
도움이 되었습니까?

해결책 2

This isn't supported in the released version of Visual C++ 2012.

There's a preview (CTP) that does have partial support for initializer lists here: http://www.microsoft.com/en-us/download/details.aspx?id=35515. But this particular code won't work even in that preview because the STL hasn't been updated to use initializer lists. This will work fine is Visual Studio 2013. I hope it may help.

다른 팁

  • Visual Studio 2012 does not support the uniform initialization syntax.
  • Visual Studio 2013 supports this code. You can see that here: Visual Studio 2013 Build
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top