C++ LINK2019 我是菜鸟,我被困住了,请帮帮我 [复制]

c++ LINK2019 i am a rookie,i was trapped .please help me [duplicate]

提问人:user3631068 提问时间:3/26/2015 最后编辑:seheuser3631068 更新时间:3/26/2015 访问量:160

问:

我认为我的问题是来自班级汽车;但是我找不到,请帮帮我。

#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 停车场管理系统
C++ 语言:LNK2019

评论

3赞 Luchian Grigore 3/26/2015
请发布完整的错误消息。(下次格式化代码)
0赞 AndyG 3/26/2015
此代码不会编译。发布 MCVE
0赞 user3631068 3/26/2015
现在可以吗?对不起,我以前没有用过。
1赞 Lightness Races in Orbit 3/26/2015
注册时,您会看到大量说明。10个月前。可惜你没有读过它们!
0赞 sehe 3/26/2015
这是一枚炸弹

答:

-1赞 Rupesh Yadav. 3/26/2015 #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;
}

您忘记了放置 before class 及其构造函数。
检查一下: http://ideone.com/YZN2EA
template<typename T>

评论

0赞 user3631068 3/26/2015
对不起,我忘了复制它,我以前写过。
0赞 Rupesh Yadav. 3/26/2015
好吧,但不要重复这个,哈哈哈哈...... :P
0赞 user3631068 3/26/2015
ee......还有其他错误吗?
0赞 Rupesh Yadav. 3/26/2015
不,你可以在这里编译:ideone.com/YZN2EA