I tried to create my own structure. So I wrote this piece of code.
struct node
{
int val, id;
node(int init_val, int init_id)
{
val = init_val;
id = init_id;
}
};
node t[100];
int main()
{
...
}
I tried to compile my program. But I got an error:
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
This will fix your error.
You should declare default constructor.
will try to initialise the array by calling a default constructor for
node
. You could either provide a default constructoror, rather verbosely, initialise all 100 elements explicitly
or, since you're using C++, use
std::vector
instead, appending to it (usingpush_back
) at runtime