c ++ LINK2019我是新手,我被困了。请帮助我

时间:2015-03-26 12:22:12

标签: c++ lnk2019

我认为我的问题来自Car Car;但是我找不到它,请帮助我。

#include <iostream>
void main()
{
    int n = rand() % 6;
    int time = 1;
    for (int i = 0; i < n; i++) {
        Car<int> car1; // this place is error
        // BianDao.QInsert(car);
        int n = 0;
        car1.Get_Car_Number(n);
        cout << n << endl;
    }
}

template <class T>
class Car {
    int Car_Number;
    int Start_Time;
    int Out_Time;

public:
    Car(const T &item = 0);
    ~Car();
    bool Get_Car_Number(T &item)
    {
        item = Car_Number;
        return true;
    }
    bool Get_Start_Time(T &item);
    bool Get_Out_Time(T &item);
    bool Set_Start_Time(const T &item);
};

template <class T>
Car<T>::Car(const T &item)
    : Start_Time(item)
{
    Car_Number = 9999 + rand() % 99999;
}

错误:

error LNK2019: 无法解析的外部符号 "public: __thiscall
Car<int>::~Car<int>(void)" (??1?$Car@H@@QAE@XZ),该符号在函数 _main
中被引用  C:\Users\Administrator\documents\visual studio
2013\Projects\停车场管理系统\停车场管理系统\main.obj 停车场管理系统

1 个答案:

答案 0 :(得分:-1)

现在它正在运作:

#include <iostream>
template<typename T>  // was missing
class Car{
int Car_Number;
int Start_Time;
int Out_Time;
public:
    Car(const T&item = 0);
    ~Car();
    bool Get_Car_Number(T&item){
        item = Car_Number; return true;
    }
    bool Get_Start_Time(T&item);
    bool Get_Out_Time(T&item);
    bool Set_Start_Time(const T&item);
};
template<typename T>    // was missing
Car<T>::Car(const T&item):Start_Time(item){//this is car's constructor
Car_Number = 9999 + rand() % 99999;
}

你忘记在课前及其构造函数中放置template<typename T> 检查一下:http://ideone.com/YZN2EA