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

What's wrong using "template and inner class"

File : NodeList.h
//----------------------------------------------------------------------
#ifndef NODELIST_H
#define NODELIST_H
#include <string>
using std::string;

template <typename T>
class NodeList
{

public:
class Node
{
public:
Node* itsPrev;
Node* itsNext;
T* itsData;
};
public:
NodeList();
Node* SearchStr( string myStr );
private:
Node* itsHeader;
Node* itsTrailer;
};
#endif

---------------------------------------------------------

NodeList.cpp
//---------------------------------------------
#include "NodeList.h"

template<typename T>
NodeList<T>::NodeList()
{
size = 0;

this->itsHeader = new Node;
this->itsTrailer = new Node;

this->itsHeader->itsNext = this->itsTrailer;
this->itsTrailer->itsPrev = this->itsHeader;
}

template<typename T>
Node* NodeList<T>::SearchStr( string myStr )
{
//for test
return NULL;
}
//-------------------------------------
----------------------- complie message----------------
1>Compiling...
1>nodelist.cpp
1>d:\play ground\oop2 lec workspace
\e_library_test_2\e_library_test_2\nodelist.cpp(33 ) : error C2143:
syntax error : missing ';' before '*'
1>d:\play ground\oop2 lec workspace
\e_library_test_2\e_library_test_2\nodelist.cpp(33 ) : error C4430:
missing type specifier - int assumed. Note: C++ does not support
default-int
1>d:\play ground\oop2 lec workspace
\e_library_test_2\e_library_test_2\nodelist.cpp(33 ) : error C2065:
'T' : undeclared identifier
1>Build log was saved at "file://d:\Play Ground\OOP2 Lec Workspace
\e_library_test_2\e_library_test_2\Debug\BuildLog. htm"
1>e_library_test_2 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

-------------------------------------------------------------------

It's seems .. "definition of SearchStr function" is making this error.
but I can't find what I should fix. :(
Anyone knows what's wrong with this code.
Oct 20 '08 #1
2 2033
Hi!

Hukkky wrote:
NodeList.cpp
//---------------------------------------------
#include "NodeList.h"

template<typename T>
NodeList<T>::NodeList()
{
size = 0;

this->itsHeader = new Node;
this->itsTrailer = new Node;

this->itsHeader->itsNext = this->itsTrailer;
this->itsTrailer->itsPrev = this->itsHeader;
}

template<typename T>
Node* NodeList<T>::SearchStr( string myStr )
{
//for test
return NULL;
}
//-------------------------------------
----------------------- complie message----------------
1>Compiling...
1>nodelist.cpp
1>d:\play ground\oop2 lec workspace
\e_library_test_2\e_library_test_2\nodelist.cpp(33 ) : error C2143:
syntax error : missing ';' before '*'
Well, the above lines are probably not your code, since nodelist.cpp
does not have 33 lines.

However, most probably the line
Node* NodeList<T>::SearchStr( string myStr )
is not valid, since there is not type called Node. However maybe you
mean Nodelist<T>::Node.

It's seems .. "definition of SearchStr function" is making this error.
but I can't find what I should fix. :(

Yep. See above.
Marcel
Oct 20 '08 #2
I see...
I changed as below and complies OK :)
thanks.

template<typename T>
typename NodeList<T>::Node* NodeList<T>::SearchStr( string myStr )
{
//for test
return NULL;
}
Oct 20 '08 #3

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

Similar topics

10
by: Average_Joe | last post by:
Hello PHP people, Was wondering if PHP5 had some sort of "nested class" functionality. I'm trying to figure out how to return an object (with a private constructor) that has access to...
10
by: Lionel B | last post by:
Greetings, I cannot figure out why the following code does not compile: --- BEGIN CODE --- typedef double ftype(double); struct A {
5
by: Jacky Yuk | last post by:
Hi all, I am new to c++ but using c for long time. Recently, I created a MFC GUI project by VC/C++ 6.0. Everything was fine until I wanted to use "template": template <typename T> class...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
9
by: Kobe | last post by:
Is there any difference in: template <class T> vs. template <typename T> ?
2
by: yinglcs | last post by:
I have the following code, which use template as the parent class of my other class. But I have "instantiated from here" compile error at this line: class C: public B2<A>. Can some one...
4
by: Gary li | last post by:
Hi, all I find "template template" class cann't been compiled in VC6 but can ok in Redhat9. I write a test program like as: template< template<class> class T> class A { }; int main() {...
3
by: Pierre Barbier de Reuille | last post by:
Hi, after reading the article " The Standard Librarian : Defining Iterators and Const Iterators" from Matt Austern:...
2
by: Lionel B | last post by:
I frequently seem to run into the following annoyance regarding template class specialisation: I have a template class which implements, for a general template parameter, some basic functionality...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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...
0
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...
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,...

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.