Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What's wrong using "template and inner class"

Reply
Thread Tools

What's wrong using "template and inner class"

 
 
Hukkky
Guest
Posts: n/a
 
      10-20-2008
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.
 
Reply With Quote
 
 
 
 
Marcel Müller
Guest
Posts: n/a
 
      10-20-2008
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
 
Reply With Quote
 
 
 
 
Hukkky
Guest
Posts: n/a
 
      10-20-2008
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;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
failing to instantiate an inner class because of order of inner classes Pyenos Python 2 12-27-2006 11:19 PM
Design patterns using anonymous inner classes Scott Simpson Java 8 01-13-2006 03:35 AM
using variable in an Inner class db Java 1 08-27-2004 11:46 AM
inner classes in python as inner classes in Java Carlo v. Dango Python 14 10-19-2003 08:49 AM
Cant Bind a data from a multi-table Inner Join using C# Gareth Stretch ASP .Net 0 06-26-2003 12:59 PM



Advertisments