0

I have worked on this same problem for three days, I can't do anything about it. Please Help!!

This is not a duplicate of a question with a similar name. The name is similar, but the problem is completely different.

May have something to do with External Dependencies is what I am told.

I am posting all of my code, and if I need to post more info please ask!

list_test.cpp This does more, but this is where it messes up.

 #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;
}
 }

Here is the error message:

 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 ==========
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
  • 3
    FWIW, it is probably not a good idea to give your class the same name as an STL container and import both your namespace and the `std` namespace through a `using` directive. Have you tried a different name? Just as an experiment... – Andy Prowl Jan 26 '13 at 01:22
  • (Btw, I am assuming you tried to cleanup everything and rebuild. If you did not, try that as well) – Andy Prowl Jan 26 '13 at 01:25
  • 4
    ...and so `using namespace` finds its next victim. Tutorial writers who recommend it should be tied to a lamppost and forced to listen to a computer voice reading g++ template error messages. – us2012 Jan 26 '13 at 01:31
  • "*I am posting all of my code, and if I need to post more info please ask!*" - We don't want more of your code, we want **less**. You would have received an answer by now if you had posted the smallest possible complete test case that demonstrates the problem. See http://SSCCE.ORG for more info. – Robᵩ Jan 26 '13 at 02:16
  • Your test program works fine for me with g++ 4.7.2. What compiler are you using? – Robᵩ Jan 26 '13 at 02:20
  • What happens when you remove the "using namespace std" line? – arayq2 Jan 26 '13 at 02:51
  • 1
    @Rob Well I did post less code here and got no answer: http://stackoverflow.com/questions/14514379/unresolved-external-symbol-on-operator-in-template. I resorted to posting all my code. Thanks for the interest, I've tried all of it. I'm using Visual Studio 2012 C++ Express. – SirRupertIII Jan 26 '13 at 04:49

2 Answers2

1

I wouldn't necessarily defend its use but I don't think your problem is the using statement. I can't see any reason to have collision when you don't #include <list>. That would be:
error C2872: 'list' : ambiguous symbol....

From what the message says I would start by making sure that list.h is where it's supposed to be.

Also, you can always reference VS error codes like the LNK2019 you're getting and check the examples against your issues.

ChiefTwoPencils
  • 13,548
  • 8
  • 49
  • 75
1

Thank you for the answers! I found the problem. I had two of the same list.h files in the External Dependencies, so I just deleted it and it compiled. I don't know how it happened, I guess I set up my program incorrectly.

SirRupertIII
  • 12,324
  • 20
  • 72
  • 121