Hi, so i tried running my code and i keep getting the error "call to implicitly-deleted default constructor of 'node'. My code is as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//.h file
typedefstruct node * point
struct node{
string data;
node *next
}
class list{
somefunction(int);
//.cpp file
somefunction(int)
{
point ptr1, ptr2;
ptr1 = new node;
I get the error at the line "ptr1 = new node;" I tried putting a default constructor for my node struct and that fixed the problem but a new problem arises. It states that i have a linker error after i compile it with a default constructor.
Thank you for your reply. However when i did that it states "Constructor for 'node' must explicitly initialize the member 'data' which does not have a default constructor"
yes, it is a custom class. I just put string because I didn't think it had anything to do with the problem. It was a custom class called "employee". I put a default constructor employee::employee{}; and my program ran normally. There was no more errors. Why is this?
Because when object is constructed, it should initialize its members. If you do not specify otherwise, it does it by calling their default constructors. If those are nonexistant or inaccessible, compilation fails.
> I just put string because I didn't think it had anything to do with the problem
It is good to simplify the code, just make sure that the code does reproduce the problem.
If you want to use another constructor you can call it using an initialization list