Thread: C++ pointer to class problem

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    62

    C++ pointer to class problem

    Hey all.
    Right now I'm working on algorithms, and so I wanted to make my own Linked List class (I do realize I'm reinventing the wheel, doesn't make it less fun :P).

    I've also started using eclipse yesterday (just a note, in case I simply messed the IDE up).

    Ok. So my Linked List contains 2 pointers, an integer (size) and a bunch of methods. Every item in the Linked List is called LinkedObject (which is a struct).

    Linked Object looks like so:
    Code:
    template <class T>
    struct LinkedObject
    {
    	T object;
    	LinkedObject* next;
    };
    This is all fine, so I started making the LinkedList class, and ran into this problem:

    Code:
    template <class T>
    class LinkedList
    {
    private:
    	LinkedObject* ListBegin, ListEnd; //2 pointers
    	int size; //size integer
    public:
    	void Append(T ToAdd ) /*this first method adds an object to the end of the list*/
    	{
    		if(size==0)//if it's empty...
    		{
    			ListBegin = new LinkedObject<T>; /*make a new object in the beginning since the list is empty*/
    			ListBegin->object = ToAdd; /*NOTE THIS LINE! seemingly innocent statement: set the object in the LinkedObject ListBegin(which is a pointer) to the value the user wants to add*/
    		}
    	}
    };
    the error is there, eclipse throws me a "Field object could not be resolved and i have absolutely no idea onto why it would do that.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code:
    LinkedObject* ListBegin, ListEnd; //2 pointers
    LinkedObject is class template.

    Secondly, the comment is also wrong
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    62
    Quote Originally Posted by anon View Post
    Code:
    LinkedObject* ListBegin, ListEnd; //2 pointers
    LinkedObject is class template.
    Thanks! Adding a <T> before the star fixed it.

    Now to give you a +1...
    Quote Originally Posted by anon View Post
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 08-06-2011, 11:58 AM
  2. problem - pointer arrays to class
    By miroslav_karpis in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2009, 04:45 AM
  3. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 05:30 AM
  4. Replies: 25
    Last Post: 10-29-2007, 04:08 PM
  5. finding derived class type of a pointer to a base class
    By LinuxCoder in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2006, 11:08 AM

Tags for this Thread