472,374 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

problem with inner class involving template

Please check this program...When I compiles it in VC.net, it gives the
following error:
===============
Common\Lib\PList.h(115): error C2440: '=' : cannot convert from
'ListNode *' to 'List<T>::ListNode *'
with
[
T=float
]
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
project\Source\Levelmgr.cpp(198) : while compiling
class-template member function 'List<T>::Iterator::Iterator(List<T>
*)'
with
[
T=float
]
project\Source\Levelmgr.cpp(15) : see reference to class
template instantiation 'List<T>::Iterator' being compiled
with
[
T=float
]

===============
when I tried to change it to

template<typename T>
List<T>::ListNode * List<T>::Head(void)
{
return m_pstart;
}

instead of

template<typename T>
ListNode * List<T>::Head(void)
{
return m_pstart;
}, it gives the error:
======================
Common\Lib\PList.h(89): error C2065: 'T' : undeclared identifier
======================

Could anyone please explain what is wrong here?

Thanks,

CODE:
__________________________________________________ ____________________________

#ifndef PLIST__H__
#define PLIST__H__

class ListNode;

/**
LinkedList class
*/
template<typename T>
class List
{

public:
void Init(void);
void Cleanup(void);
BOOL AddItem(T data);
ListNode * Head(void);

private:
/**
A node of the list
*/
class ListNode
{
ListNode(void){}
ListNode(const T& data, ListNode *next):m_data(data), m_next(next){}

public:
T m_data; ///<data
ListNode *m_next; ///<link to the next node
};

uint16 m_num_elems; ///<Number of elements in the list
ListNode *m_pstart; ///<Pointer to the first element of the list

public:
class Iterator
{
public:
Iterator(List<T> *plist);
void operator++(void);
T Content(void);

private:
List<T> *m_plist; ///<Pointer to the list
ListNode *m_plistnode; ///<Pointer to the listnode
};
};

//////////////////////////////////////////////////////////
//List
//////////////////////////////////////////////////////////

/**
Init List
*/
template<typename T>
void List<T>::Init(void)
{
m_num_elems = 0;
m_pstart = NULL;
}

/**
Add item to the front of the list
\param[in] data Data to be stored in the list
*/
template<typename T>
BOOL List<T>::AddItem(T data)
{
BOOL res = TRUE;
m_pstart = new ListNode(data, m_pstart);
if(!m_pstart)
{
LOG_FAILED;
ERXIT;
}
m_num_elems++;
xit:
LOG_IF_FAILED;
return res;
}

/**
Get the pointer to the first item in the list
*/
template<typename T>
ListNode * List<T>::Head(void)
{
return m_pstart;
}

/**
Cleanup routine
*/
template<typename T>
void List<T>::Cleanup(void)
{

}

////////////////////////////////////////////////////////////
//Iterator
///////////////////////////////////////////////////////////

/**
CTOR for iterator
\param[in] plist Pointer to list
*/
template<typename T>
List<T>::Iterator::Iterator(List<T> *plist)
:m_plist(plist)
{
m_plistnode = plist->Head();//<------ERROR
}

/**
Increment operator
*/
template<typename T>
void List<T>::Iterator::operator++(void)
{
m_plistnode = m_plistnode->m_next;
}

/**
Get the content of the node iterator currently points
return content of the node iterator currently points
*/
template<typename T>
T List<T>::Iterator::Content(void)
{
return m_plistnode->m_data;
}

#endif//PLIST__H__
Jul 23 '05 #1
1 2058
darkstorm wrote:
Please check this program...When I compiles it in VC.net, it gives the
following error:
=============== [...]
when I tried to change it to

template<typename T>
List<T>::ListNode * List<T>::Head(void)
Shouldn't this be

template<typename T>
typename List<T>::ListNode * List<T>::Head()

???
{
return m_pstart;
}
[...]


Anyway, see my other reply too.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
0
by: r5 | last post by:
I'm using the MIPSpro Compiler and having trouble defining a function template (involving array size specifiers as template arguments) inside a class. The same definition compiles fine outside...
2
by: Thomas Lorenz | last post by:
Hello, im working on a problem related to smart pointers. If the following is legal C++ A* a(new A()); B* b; b = a; I want to be able to do the following:
3
by: darkstorm | last post by:
Hi, Please have a look at this code when compiling it is giving error: error C2440: '=' : cannot convert from 'ListNode *' to 'List<T>::ListNode *' with when I added List<T>:: before...
4
by: Mark P | last post by:
I'm trying to define a templatized version of operator<< to print out information about a template class. The code below won't compile. (error: no match for std::ostream& << Outer<int>::Inner&) ...
5
by: Martijn Mulder | last post by:
A construction like this: class Outer { class Inner:Outer { } } compiles without problem but does it introduce infinity?
1
by: mrstephengross | last post by:
I'm making progress on mixing templates with friends (sounds like a drinking game, huh?). Anyway, here's the situation. I've got an "Outer" class with a private "Inner" class (sub-class,...
1
by: Jens Mander | last post by:
The following code generates errors when compiled using VC++ 7.1. However, gcc 3.2.2 and comeau online have no problems with it. Is this illegal code or a compiler bug? If it is the latter; was it...
3
by: Christof Warlich | last post by:
Hi, I need to specialize an inner template class, but gcc refuses to compile. Here is a minimal example exposing the issue: template<int astruct Outer { template<int bstruct Inner { }; };...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.