正在为链表c++创建DataType



我正在尝试创建一个链表,其中节点中的数据是Car类型的自定义DataType,它保存车库中汽车的到达时间和离开时间。当我运行代码时,我一直得到

lnk2019错误:未解析的外部符号"public:__thiscall Car::Car(void)"(?0Car@@QAE@XZ)在函数"public:__thiscall CarNode::CarNode(void)"中引用(?0CarNode@@QAE@XZ)。

这是代码:

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class Car
{
public:
    Car();
    int getArrival()
    {
        return arrival;
    };
    int getDeparture()
    {
        return departure;
    };
    int arrival = 0;
    int departure = 0;
};
class CarNode
{
public:
    Car data;
    CarNode* next;
};
class CarLinkedList
{
public:
    CarLinkedList(Car &e)  
    {
        cout << "Constructor for Car:  " << e.getArrival() << endl;
        head = new CarNode; 
        head->data = e;
        head->next = NULL;
    }
    void addFront(Car& e)       
    {
        CarNode *v = new CarNode;           
        v->data = e;                    
        v->next = head;                 
        head = v;                       
        cout << "addFront: new head is " << head->data.getArrival() << endl;
    } 
private:
    CarNode *head;              // pointer to the head of list
};
int main()
{
    Car chevy;
    CarLinkedList *s;
    s = new CarLinkedList(chevy);
    s->printSLL();
    cin.get();
}

您的代码中有以下内容:

class Car {
    public:
        Car();

但我在任何地方都看不到它的定义:

Car::Car() {
    ...
}

相关内容

  • 没有找到相关文章

最新更新