inherited variables in template class not inheriting

This is a discussion on inherited variables in template class not inheriting within the C++ Programming forums, part of the General Programming Boards category; okay, i'll just show you the code first: Code: template <class T> class PULT_Layer { public: virtual ~PULT_Layer() { } ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    2

    inherited variables in template class not inheriting

    okay, i'll just show you the code first:


    Code:
    template <class T>
    class PULT_Layer
    {
    public:
    	virtual ~PULT_Layer() { } // Probably needed
    	virtual void clear() = 0;
    
    	virtual UINT return_debug_code () const { return 0; }
    		
    	PULT_Layer<T> * m_pParent;
    	UCHAR m_uc_index_in_parent;
    				
    	UINT number_slots_used;
    };
    
    template <class T>
    class PULT_NonFinal_Layer : public PULT_Layer<T>
    {
    public:
    	PULT_NonFinal_Layer(PULT_Layer<T> * pParent, UCHAR uc_index_in_parent);
    	virtual ~PULT_NonFinal_Layer();
    	virtual void clear();
    
    	virtual UINT return_debug_code () const { return 1; }
    
    	PULT_Layer<T> * layer[256];
    };
    now, here's the definition for the PULT_NonFinal_Layer constructor:


    Code:
    template <class T>
    PULT_NonFinal_Layer<T>::PULT_NonFinal_Layer(PULT_Layer<T> * pParent, UCHAR uc_index_in_parent)
    {
    	m_pParent = pParent;
    	m_uc_index_in_parent = uc_index_in_parent;
    	number_slots_used = 0;
    	for (UINT ui = 0; ui < 256; ++ui) { layer[ui] = 0; }
    }


    this works just dandy under MSVCPP6, but when attempting to compile this with dev-cpp i get the following error:


    POG_UID.h: In constructor `PULT_NonFinal_Layer<T>::PULT_NonFinal_Layer(PULT_ Layer<T>*, UCHAR)':
    POG_UID.h:112: error: `m_pParent' undeclared (first use this function)

    is there something that i need to do to the code?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >this works just dandy under MSVCPP6
    A lot of broken code works just dandy under VC++ 6.

    >is there something that i need to do to the code?
    The problem is because of dependent name lookup. You can sidestep it by qualifying the names with 'this->', or specifying PULT_Layer<T>:: for each of the names whenever you use them. The former is cleaner though:
    Code:
    template <class T>
    PULT_NonFinal_Layer<T>::PULT_NonFinal_Layer(PULT_Layer<T> * pParent, UCHAR uc_index_in_parent)
    {
    	this->m_pParent = pParent;
    	this->m_uc_index_in_parent = uc_index_in_parent;
    	this->number_slots_used = 0;
    	for (UINT ui = 0; ui < 256; ++ui) { layer[ui] = 0; }
    }
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    2
    ^_^

    You have just made a very tired, slightly crazed programmer very very happy. thank you.

  4. #4
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    then its dev cpp compiler that is broken... perhaps a old gcc ?

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >then its dev cpp compiler that is broken...
    How so? It's giving an error about a legitimate problem that requires a diagnostic message because it's a constraint violation. That's the correct behavior. A compiler that lets the code slide is broken, not the other way around.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function template has already been defined
    By Elysia in forum C++ Programming
    Replies: 19
    Last Post: 04-14-2009, 10:17 AM
  2. Though implementation problem
    By Elysia in forum C++ Programming
    Replies: 296
    Last Post: 05-31-2008, 01:02 PM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  5. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21