Thread: Pointers to (templated) classes being declared

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    50

    Pointers to (templated) classes being declared

    hi,

    I'm having troubles with the following class declaration:

    Code:
    template <class TYPE> class LList
    {
    public:
    	LList();
    	~LList();
    
    	TYPE*	obj;
    
    	LList<TYPE>* next, prev;
    
    	LList<TYPE>* Add(TYPE* nObj);
    	LList<TYPE>* Insert(TYPE *nObj);
    	void Remove();
    };
    The compiler (MSVC8 Express) complains that :

    Code:
    helpers.cpp(13) : error C2460: 'LList<TYPE>::prev' : uses 'LList<TYPE>', which is being defined
    But, i'm sure i've included member pointers in this way in a non templated class before. Can anyone shed any light on this?

    thanks in advance

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    50
    As usual, i stared at this for a morning, posted a question and immediately spotted the solution. Needed another * before the 'prev' variable name (have to admit, i find it counter-intuitive that you can declare objects and pointers in the same line)

    Code:
    template <class TYPE> class LList
    {
    public:
    	LList();
    	~LList();
    
    	TYPE*	obj;
    
    	LList<TYPE>* next,* prev;
    
    	LList<TYPE>* Add(TYPE* nObj);
    	LList<TYPE>* Insert(TYPE *nObj);
    	void Remove();
    };

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Many people do. I'm afraid that's just legacy from C. You can declare references and array on the same line, too.
    To avoid making that mistake, I never declare more than one pointer in a statement.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. storing pointers to a templated class in a vector
    By rt454 in forum C++ Programming
    Replies: 4
    Last Post: 01-19-2009, 03:04 AM
  2. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  3. pointers as members of classes
    By punkrockguy318 in forum C++ Programming
    Replies: 2
    Last Post: 11-21-2003, 06:35 PM
  4. Function Pointers to Templated Functions
    By Speedy5 in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2003, 08:11 AM
  5. Pointers to inherited classes
    By sean in forum C++ Programming
    Replies: 1
    Last Post: 11-03-2001, 03:04 PM