我尝试创建自己的结构。因此,我编写了这段代码。
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];
会默认构造每个元素,但是node
没有默认构造函数。 - David G