473,602 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

template<typena me T>
List<T>::ListNo de * List<T>::Head(v oid),

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<typena me 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(d ata), 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<typena me T>
void List<T>::Init(v oid)
{
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<typena me T>
BOOL List<T>::AddIte m(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<typena me T>
ListNode * List<T>::Head(v oid)
{
return m_pstart;
}

/**
Cleanup routine
*/
template<typena me T>
void List<T>::Cleanu p(void)
{

}

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

/**
CTOR for iterator
\param[in] plist Pointer to list
*/
template<typena me T>
List<T>::Iterat or::Iterator(Li st<T> *plist)
:m_plist(plist)
{
m_plistnode = plist->Head();
}

/**
Increment operator
*/
template<typena me T>
void List<T>::Iterat or::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<typena me T>
T List<T>::Iterat or::Content(voi d)
{
return m_plistnode->m_data;
}

#endif//PLIST__H__
Jul 23 '05 #1
3 1744
darkstorm wrote:
Please have a look at this code

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

template<typena me T>
List<T>::ListNo de * List<T>::Head(v oid),

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.********@com Acast.net> wrote in message news:<Vk******* ************@ne wsread1.mlpsca0 1.us.to.verio.n et>...
darkstorm wrote:
Please have a look at this code

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

template<typena me T>
List<T>::ListNo de * List<T>::Head(v oid),

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.********@com Acast.net> wrote in message news:<Vk******* ************@ne wsread1.mlpsca0 1.us.to.verio.n et>...
darkstorm wrote:
Please have a look at this code

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

template<typ ename T>
List<T>::Lis tNode * List<T>::Head(v oid),

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
3333
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 to turn a previously made String class that deals with char's into a templated String class that uses the template parameter C instead of char. I thought it would be fairly simple to do this exercise, but I encoutered many errors for my...
4
6380
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. How do I do this? Also, I want to have a data member for
8
2689
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 to do this, using the SFINAE principle. Here is a simple example showing what I am trying to do: 1 #include <iostream.h> 2 #include <boost/utility/enable_if.hpp> 3
0
1352
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 templates: ------------------------------------------ in file "Model.h":
21
4057
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 A { std::vector<B*> Bs; public:
5
2424
by: Martijn Mulder | last post by:
A construction like this: class Outer { class Inner:Outer { } } compiles without problem but does it introduce infinity?
1
1610
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, technically). I want to declaring an unrelated "Thing" class to be a friend of the inner class. However, since the inner class is private, the compiler complains. Here's what the code looks like: ====================================================...
3
2380
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. Here is the Query
3
4265
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 { }; }; template<int atemplate<struct Outer<a>::Inner<0{
0
7920
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6730
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.