Thread: Been out of C++ for a while, think i've made a stupid mistake with this code....

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    3

    Been out of C++ for a while, think i've made a stupid mistake with this code....

    I've been using java for the last couple of months so i've just recently got back into C++ and I need to make a simple LinkedList class for a project. I believe everything is coded just fine it's just something in my main declared wrong. Here is my main:

    Code:
    #include "Exception.h"
    #include "Exception.cpp"
    
    #include "LinkedList.h"
    #include "Node.h"
    #include "IndexOutOfBounds.h"
    #include <iostream>
    using namespace std;
    
    int main()
    {
    LinkedList<int> a;
    
    
    return 0;
    }
    I just went crazy and starting including everything. I even re did my program without templating and it still gave me the same error. The exact error is:


    Main.cpp: In function `int main()':
    Main.cpp:12: `LinkedList' undeclared (first use this function)
    Main.cpp:12: (Each undeclared identifier is reported only once
    Main.cpp:12: for each function it appears in.)
    Main.cpp:12: parse error before `>'


    The problem has to be in that bit of code but if you need the other files i can supply that. I have a feeling this is a very stupid problem caused from my time off. Thanks in advance guys.

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    Is that a custom implementation?
    Why not just use the stl
    #include <list>

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    post the code for LinkedList.h
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    3
    Code:
    // LinkedList.h
    
    #include "Node.h"
    #include "IndexOutOfBounds.h"
    #include <iostream>
    
    #ifndef LINKED_LIST_H
    #define LINKED_LIST_H
    
    namespace DonathList {
       using Donath::IndexOutOfBounds;
       using std::ostream;
    
       template <class T>
       class LinkedList {
          public:
             LinkedList();
    
             LinkedList(const LinkedList<T>&);
    
             virtual ~LinkedList();
    
             LinkedList<T>& operator=(const LinkedList<T>&);
    
             T getElementAt(int position) const throw (IndexOutOfBounds);
    
             T operator[](int position) const throw (IndexOutOfBounds);
    
             void insert(T element, int position) throw (IndexOutOfBounds);
    
             void append(T element);
     
             T remove(int position) throw (IndexOutOfBounds);
    
             // Returns position of element in the list, -1 if not found
             int find(T value) const;
    
             bool isEmpty() const;
    
             template<class S>
             friend ostream& operator<< (ostream&, const LinkedList<S>&);
    
          private:
             Node<T>* head;
       };
    }
    #endif

    I could do that curious but also I want to figure out what went wrong with the code i have.

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    My guess is you have to qualify the name because it is in a DonathList::LinnkedList

    I am not sure if you can simple add
    using DonathList::LinkedList as I haven't used my own namespaces before but I bet this is the problem.

  6. #6
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Im my experience trying to compile *template class* in MSVC++ 6.0 and .NET, I learned that I had to put the declaration and definition in *one file*.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    3
    Quote Originally Posted by curlious
    My guess is you have to qualify the name because it is in a DonathList::LinnkedList

    I am not sure if you can simple add
    using DonathList::LinkedList as I haven't used my own namespaces before but I bet this is the problem.
    Thanks bro, you hit the nail on the head. The last thing i remember doing with C++ is user namepaces and I forgot to include my own, doh. Good work man.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  2. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  3. Replies: 1
    Last Post: 03-21-2006, 07:52 AM
  4. Replies: 4
    Last Post: 01-16-2002, 12:04 AM
  5. Code structure of this program I made.
    By Seron in forum C++ Programming
    Replies: 0
    Last Post: 01-10-2002, 11:35 AM