472,986 Members | 3,137 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,986 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 2009
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.