"неразрешенный внешний символ" в классе шаблона

Я работал над этой же проблемой три дня, ничего не могу с этим поделать. Пожалуйста помоги!!

Это не дубликат вопроса с похожим названием. Название похожее, но проблема совершенно иная.

Может быть, как-то связано с внешними зависимостями - вот что мне говорят.

Я публикую весь свой код, и если мне нужно разместить больше информации, пожалуйста, спросите!

list_test.cpp Это делает больше, но это то, где это портит.

 #include <cctype>       // Provides toupper
 #include <iostream>     // Provides cout and cin
 #include <cstdlib>      // Provides EXIT_SUCCESS
 #include "list.h"  // With value_type defined as double
 #include "Node.h"
 #include "Iterator.h"
 using namespace std;
 using namespace list_1;

 int main( )
 {
     list<double> test;
 }

iterator.h

 // Template CLASS PROVIDED: Iterator 

 #pragma once
 #include "Node.h"

 namespace list_1
 {
template<typename T>
class Iterator
{
    public:
    Iterator<T> (Node<T> *np);
    // precondition: is_item is true
    // post condition n points to the next item in the list
    void operator++();
    // precondition: 
    // postcondition: returns true if there is a valid item
    bool is_item();
    // precondition: is_item == true
    // postcondition returns data that n is pointing at
    T operator* ();

    private:
    Node<T>* n;

};

template<typename T>
Iterator<T>::Iterator (Node<T> *np)
{
    n = np;
}

template<typename T>
void Iterator<T>::operator++()
{
    assert(is_item( ) == true);

    n = n->next;
}

template<typename T>
bool Iterator<T>::is_item()
{
    return (n->data != NULL);
}

template<typename T>
T Iterator<T>::operator* ()
{
    assert(is_item( ) == true);

    return n->data;
}
 }

Node.h

 #pragma once

 namespace list_1
 {
template <typename T>
struct Node
{
    T data;
    Node<T> *next;

    // Constructor
    // Postcondition: 
    Node<T> (T d);
};

template <typename T>
Node<T>::Node(T d)
{
    data = d;
    next = NULL;
}
 }

list.h

 #include "Node.h"
 #include "Iterator.h"

 namespace list_1
 {
template <typename T>
class list
{
    public:
        // CONSTRUCTOR
        list();
        // postcondition: all nodes in the list are destroyed.
        ~list();
        // MODIFICATION MEMBER FUNCTIONS
        //postcondition: entry is added to the front of the list
        void insert_front(const T& entry);
        //postcondition: entry is added to the back of the list
        void add_back(const T& entry);
        // postcondition: all nodes with data == entry are removed from the list
        void remove_all(const T& entry);
        // postcondition: an iterator is created pointing to the head of the list
        Iterator<T> begin(void);
        // CONSTANT MEMBER FUNCTIONS
        // postcondition: the size of the list is returned
        int size( ) const;
    private:
        Node<T>* head;
};

template <typename T>
list<T>::list( )
{
    head = NULL;
}

template <typename T>
list<T>::~list()
{

}

template <typename T>
void list<T>::insert_front(const T& entry)
{
    // head = new node(entry, head);
}

template <typename T>
void list<T>::add_back(const T& entry)
{

}

template <typename T>
void list<T>::remove_all(const T& entry)
{

}

template <typename T>
Iterator<T> list<T>::begin(void)
{
    //Iterator<T> traverse( );
    //return traverse;
}

template <typename T>
int list<T>::size( ) const
{
    int size = 0;
    Node<T> *tempPoint = head;

    for (tempPoint = head; tempPoint != NULL; tempPoint = tempPoint->next)
    {
        size ++;
    }

    return size;
}
 }

Вот сообщение об ошибке:

 1>------ Build started: Project: CS2420LinkedList, Configuration: Debug Win32 ------
 1>list_test.obj : error LNK2019: unresolved external symbol "public: __thiscall list_1::list<double>::~list<double>(void)" (??1?$list@N@list_1@@QAE@XZ) referenced in function _main
 1>list_test.obj : error LNK2019: unresolved external symbol "public: __thiscall list_1::list<double>::list<double>(void)" (??0?$list@N@list_1@@QAE@XZ) referenced in function _main
 1>C:\Users\KyleYas\Documents\Visual Studio 2010\Projects\CS2420LinkedList\Debug\CS2420LinkedList.exe : fatal error LNK1120: 2 unresolved externals
 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

2 ответа

Решение

Спасибо за ответы! Я нашел проблему. У меня было два одинаковых файла list.h во Внешних зависимостях, поэтому я просто удалил их и скомпилировал. Я не знаю, как это случилось, наверное, я неправильно настроил программу.

Я бы не стал защищать его использование, но я не думаю, что ваша проблема using заявление. Я не вижу причин для столкновения, когда ты не #include <list>, Это было бы:
error C2872: 'list' : ambiguous symbol...,

Из того, что говорится в сообщении, я бы начал с того, чтобы убедиться, что list.h где это должно быть.

Кроме того, вы всегда можете ссылаться на коды ошибок VS, такие как LNK2019, которые вы получаете, и сверять примеры с вашими проблемами.

Другие вопросы по тегам