Compiler bug? - by TCool_520

Status : 

 


1
1
Sign in
to vote
ID 836528 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 3/18/2014 11:04:20 PM
Access Restriction Public

Description

I saw this tutorial online.
// pointer to classes example
#include <iostream>
using namespace std;

class Rectangle {
  int width, height;
public:
  Rectangle(int x, int y) : width(x), height(y) {}
  int area(void) { return width * height; }
};


int main() {
  Rectangle obj (3, 4);
  Rectangle * foo, * bar, * baz;
  foo = &obj;
  bar = new Rectangle (5, 6);
  baz = new Rectangle[2] { {2,5}, {3,6} };
  cout << "obj's area: " << obj.area() << '\n';
  cout << "*foo's area: " << foo->area() << '\n';
  cout << "*bar's area: " << bar->area() << '\n';
  cout << "baz[0]'s area:" << baz[0].area() << '\n';
  cout << "baz[1]'s area:" << baz[1].area() << '\n';       
  delete bar;
  delete[] baz;
  return 0;
}


But somehow, it runs perfectly on Visual Studio 2013.
But when I try to run it on VS 2012 ultimate, 
I have the following errors:

1>c:\users\danny\documents\visual studio 2012\projects\class\class\pointer_to_class.cpp(18): error C2143: syntax error : missing ';' before '{'
1>c:\users\danny\documents\visual studio 2012\projects\class\class\pointer_to_class.cpp(18): error C2512: 'Rectangle' : no appropriate default constructor available
1>c:\users\danny\documents\visual studio 2012\projects\class\class\pointer_to_class.cpp(18): error C2143: syntax error : missing ';' before '}'
1>c:\users\danny\documents\visual studio 2012\projects\class\class\pointer_to_class.cpp(18): error C2143: syntax error : missing ';' before ','
Sign in to post a comment.
Posted by Microsoft on 4/2/2014 at 3:37 PM
Hi TCool_520,

Universal initialization syntax was first implemented in Visual Studio 2013, and is not available in earlier versions of the product.

Karl Niu
Visual C++ Team
Posted by Microsoft on 3/19/2014 at 1:28 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information. If you require immediate assistance with this issue, please contact product support at http://support.microsoft.com/ph/1117.
Posted by Microsoft on 3/18/2014 at 11:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If you require immediate assistance with this issue, please contact product support at http://support.microsoft.com/ph/1117.