我試圖創建自己的結構。所以我寫了這段代碼。C++ struct構造函數
struct node
{
int val, id;
node(int init_val, int init_id)
{
val = init_val;
id = init_id;
}
};
node t[100];
int main()
{
...
}
我試圖編譯我的程序。但是,我得到了一個錯誤:
error: no matching function for call to 'node::node()'
note: candidates are:
note: node::node(int, int)
note: candidate expects 2 arguments, 0 provided
note: node::node(const node&)
note: candidate expects 1 argument, 0 provided
'node t [100];'default-constructs each element,but'node' does not have a default constructor。 – 0x499602D2
[某種類型是否需要默認構造函數以聲明它的數組?](http://stackoverflow.com/questions/2231414/does-a-type-require-a-default-constructor-in順序聲明一個數組) – bames53