2013-01-16 64 views
0

在使用Visual Studio Nov 2012 CTP C++編譯器編譯此語法時出現問題......只是想確保我沒有錯過顯而易見的東西。C++ 11使用新實例參數委託構造函數?

謝謝!

編輯:刪除標題,使其更簡單。

class Location 
{ 
public: 
    Location(); 
}; 

class Shape 
{ 
public: 
    Shape(); 
    Shape(Location location); 
}; 


// Doing this by pointer works ... 
// Shape::Shape(Location* location){} 
// Shape::Shape() : Shape(new Location()){} 

Shape::Shape(Location location) 
{ 
} 

Shape::Shape() 
    : Shape(Location()) 
    // error C2143: syntax error: missing ';' before ':' 
{ 
    // int x = 0; 
    // (void) x; // Added these two lines in some cases to get it to compile. 
    // These two lines do nothing, but get around a compiler issue. 
} 
+4

如果它是編譯器中的內部錯誤,那麼這意味着編譯器搞亂了,而不是你的代碼。在我看來,這是正確的。您可能想要在MSDN上提交錯誤報告。 –

+6

內部錯誤應該永遠不會發生。如果是這樣,它總是編譯器的一個bug,並且從來不是你的錯。 –

+2

作爲一個旁註/寵物peeve,使用'void'來表示函數不需要任何參數...... ** AUGH **! –

回答

2
// .h Simplification 
class Location 
{ 
public: 
    Location() {} 
    Location(Location const& other) {} 
}; 

class Shape 
{ 
    Shape(); 
    Shape(Location location); 
}; 

// How about by value or reference? 
Shape::Shape(Location location) 
{ 
} 

Shape::Shape(void) 
    : Shape(Location()) // error C1001: An internal error has occurred in the compiler. 
{ 
} 

int main() {} 

上面的代碼可以編譯和運行在gcc 4.7.2

我不得不做出對你的代碼進行一些更改,使其編譯。簡化事情時,儘量保留簡化的代碼編譯。 http://sscce.org/

+0

什麼是多個副本? – 0x499602D2

+0

我現在正在嘗試它,只有一個副本。 .. –

+0

@Yakk我的代碼和我的代碼有相同的錯誤。既然它在GCC上工作,而且現在我剛剛被告知最新版本的編譯器,CTP後編譯這個乾淨,我會把它記入CTP編譯器中的一個錯誤。否則,它看起來是有效的語法。我將把你的標記作爲驗證它是否正確的C++ 11語法的答案。謝謝! –

相關問題