C ++无法解析的外部符号

时间:2019-10-15 12:09:59

标签: c++ constructor

我试图使用构造函数将类对象创建到另一个类中,但出现了''无法解析的外部符号''错误。我研究示例代码,但在代码中找不到任何错误。''

LinkedList.h

#pragma once
#include <cstdint>
#include <list>
#include <iterator>
using namespace std;


template  <class T> class LinkedList
{
public:
    LinkedList();
    LinkedList(int Size);   
    list <T> data;
    int size;
    LinkedList* next;

};

LinkedList.cpp

#include "LinkedList.h"

template <class T> 
LinkedList <T> ::LinkedList() {

    size = 0;
    next = NULL;
}

template <class T>
LinkedList <T> ::LinkedList(int Size) {

    size = Size;
    next = NULL;
}

Cotp_connection.h

#pragma once
#include "connect_tcp.h"
#include "LinkedList.h"

class Cotp_connection {
public:
    Cotp_connection();
    Cotp_connection(int size);  
};

Cotp_connection.cpp

#include "Cotp_connection.h"

Cotp_connection::Cotp_connection() {
    LinkedList <uint8_t> list;
}

Cotp_connection::Cotp_connection(int size) {

    LinkedList <uint8_t> list(size);
}

LNK2019无法解析的外部符号“ public:__thiscall LinkedList :: LinkedList(void)”(?? 0?$ LinkedList @ E @@ QAE @ XZ)在函数“ public:__thiscall Cotp_connection :: Cotp_connection(void)”中引用( 0Cotp_connection @@ QAE @ XZ)kkkkk_v2

编辑:如果我以这种方式编辑了代码,它会起作用。好的,但是为什么它现在可以起作用,而不是以前呢?

Cotp_connection.cpp

Cotp_connection::Cotp_connection() {
    LinkedList <uint8_t> list();
}

Cotp_connection::Cotp_connection(int size) {

    LinkedList <uint8_t> list((size));
}   

Linkedlist.h

#pragma once
#include <cstdint>
#include <list>
#include <iterator>
using namespace std;


template  <class T> class LinkedList
{
public:
    LinkedList();
    LinkedList(int Size) :size(Size),next(NULL) {}; 
    list <T> data;
    int size;
    LinkedList* next;

};

0 个答案:

没有答案