可能重複: Why is it an error to use an empty set of brackets to call a constructor with no arguments? $ cat cons.cpp
#include <iostream>
class Matrix {
private:
int m_count;
public:
Matrix
可能重複: Why is it an error to use an empty set of brackets to call a constructor with no arguments? Most vexing parse: why doesn't A a(()); work? 這一次讓我瘋了。也許它太簡單了。 struct Foo
{
Foo() {}
Foo(co
Possible Duplicate: Why is it an error to use an empty set of brackets to call a constructor with no arguments? Constructing Objects and Calling Member functions 最近,我瞭解了一些關於構造函數,但今天我一直有麻煩的構造函數的參數設置默認值
你能解釋爲什麼這不會編譯: (這是錯誤: ../Man.cpp:33:9: error: conversion from ‘Man (*)()’ to non-scalar type ‘Man’ requested)
代碼: Man goo(){
Man m();
return m;
}
但這做: Man goo(){
return Man();
}
考慮以下代碼: int main()
{
int i(6); //this will result in i==6,but consider next initializations
int j(int());
T * p2 = new T();
}
我發現的j的值是1,但是這應該是0,因爲int()是臨時與值等於0 此外,new運算符的語法爲new ty