473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 2110
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 { }; };...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.