2
可能重複:
Do the parentheses after the type name make a difference with new?C/C++中`new`和`new()`結構有什麼區別?
在一些代碼,我最近看到一個像這樣的結構:
typedef struct MyStruct {
int numberOne;
int numberTwo;
} MYSTRUCT;
後來,我嘗試實例化使用
這些結構的一個MyStruct *pStruct = new MyStruct();
與Visual Studio 2010一起工作良好,但在另一個編譯器上出現模糊的鏈接器錯誤。花了一段時間,直到我們發現省略了這樣的大括號
MyStruct *pStruct = new MyStruct;
解決了這個問題。
那麼,這兩個調用之間的區別究竟是什麼,哪一個是正確的?
我認爲你有一個多餘的typedef(或typedef缺少的名稱),`new`返回一個指針而不是一個對象。 – 2010-12-02 11:46:24