473,394 Members | 1,841 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,394 software developers and data experts.

Inner class involving templates giving problem

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
[
T=float
]
when I added List<T>:: before ListNode for

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

it gives a series of errors like undefined identifier T.....

Please tell me what is wrong here...

Thanks,
//////////////////////////////////////////////////////////////
#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();
}

/**
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
3 1734
darkstorm wrote:
Please have a look at this code

when compiling it is giving error:
error C2440: '=' : cannot convert from 'ListNode *' to 'List<T>::ListNode *'
with
[
T=float
]
when I added List<T>:: before ListNode for

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

it gives a series of errors like undefined identifier T.....

Please tell me what is wrong here...
[...]


Post your _complete_ code again and this time put it all in one
translation unit and get rid of things like 'BOOL' or 'uint16' or define
proper typedefs for them.

The template definition is not enough to see what's wrong. We need to see
how you [attempt to] use your template.

V
Jul 23 '05 #2
Victor Bazarov <v.********@comAcast.net> wrote in message news:<Vk*******************@newsread1.mlpsca01.us. to.verio.net>...
darkstorm wrote:
Please have a look at this code

when compiling it is giving error:
error C2440: '=' : cannot convert from 'ListNode *' to 'List<T>::ListNode *'
with
[
T=float
]
when I added List<T>:: before ListNode for

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

it gives a series of errors like undefined identifier T.....

Please tell me what is wrong here...
[...]
Post your _complete_ code again and this time put it all in one
translation unit and get rid of things like 'BOOL' or 'uint16' or define
proper typedefs for them.


You can replace BOOL by int, It is just a Bolean flag. uint16 can be
replaced by unsigned int. LOG_FAILED and ERXIT can be removed. Please
do try and reply. I am stuck there.....

The template definition is not enough to see what's wrong. We need to see
how you [attempt to] use your template.

V

Jul 23 '05 #3
darkstorm wrote:
Victor Bazarov <v.********@comAcast.net> wrote in message news:<Vk*******************@newsread1.mlpsca01.us. to.verio.net>...
darkstorm wrote:
Please have a look at this code

when compiling it is giving error:
error C2440: '=' : cannot convert from 'ListNode *' to 'List<T>::ListNode *'
with
[
T=float
]
when I added List<T>:: before ListNode for

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

it gives a series of errors like undefined identifier T.....

Please tell me what is wrong here...
[...]


Post your _complete_ code again and this time put it all in one
translation unit and get rid of things like 'BOOL' or 'uint16' or define
proper typedefs for them.

You can replace BOOL by int, It is just a Bolean flag. uint16 can be
replaced by unsigned int. LOG_FAILED and ERXIT can be removed. Please
do try and reply. I am stuck there.....


Please do try *what*? The template definition is immaterial without
the code that causes it to be instantiated.

Please repost the _complete_ code that causes the error message to be
emitted.
The template definition is not enough to see what's wrong. We need to see ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^how you [attempt to] use your template.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Did you read this particular part of my reply?

You didn't provide enough information. I am not going to waste time
guessing how your template is supposed to be used. Please understand
that I have no mind reading abilities, you need to post what is needed
to solve the problem.

V
Jul 23 '05 #4

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...
4
by: Gert Van den Eynde | last post by:
Hi all, A beginners question.... I've got a template class template <class T> classA {...} In an other class, I want to pass a pointer to an instance of classA as a function argument....
8
by: Peter Collingbourne | last post by:
Hello I am trying to do some template metaprogramming involving enabling or disabling a method in a parameterised class based on some condition. I am trying to use the Boost enable_if mechanism...
0
by: Leslaw Bieniasz | last post by:
Cracow, 16.09.2004 Hi, I have a problem with compiling the following construction involving cross-calls of class template methods, with additional inheritance. I want to have three class...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
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,...
3
by: Anila | last post by:
Hi Friends, My problem with Inner join is ... first i joined two tables and i got the result. after that iam trying to join one more table its giving syn tax error in JOIN condition. ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.