Home > Software engineering >  getting an Visual studio error code C2665 in the InsertFlight method and i have no idea of the fix
getting an Visual studio error code C2665 in the InsertFlight method and i have no idea of the fix

Time:12-23

I wanted to post the whole code but i had formatting issues on the website. But I posted the codes for the structures and the InsertFlight was in a class. I will try to post full code if thats needed

struct FlightRec {
string FlightNO;
string Destination;
TimeRec Time;
FlightType Ftype;
bool Delay;
TimeRec ExpectedTime; // if the flight is delayed
};

template <class T>

struct Node {
    T entry;
    Node<T>* next;
};

// Add a flight to the list
void InsertFlight(const T& flight) {
    // Create a new node for the flight
    Node<T>* node = new Node<T>(flight);
    // Add the node to the head of the list
    node->next = head;
    head = node;
}

CodePudding user response:

You never defined a constructor for Node so I'm not sure what you're expecting this to do.

Node<T>* node = new Node<T>(flight);

You can define a constructor that accepts a T and sets next to nullptr, then your new should work.

template <class T>
struct Node {
    Node(const T& _entry) : entry(_entry) {}
    T entry;
    Node<T>* next = nullptr;
};
  •  Tags:  
  • c
  • Related