What's wrong using "template and inner class"

Discussion in 'C++' started by Hukkky, Oct 20, 2008.

  1. Hukkky

    Hukkky Guest

    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.
    Hukkky, Oct 20, 2008
    #1
    1. Advertising

  2. 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
    Marcel Müller, Oct 20, 2008
    #2
    1. Advertising

  3. Hukkky

    Hukkky Guest

    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;
    }
    Hukkky, Oct 20, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ed
    Replies:
    1
    Views:
    655
  2. KathyB
    Replies:
    0
    Views:
    588
    KathyB
    Jul 1, 2003
  3. Brian Birtle
    Replies:
    3
    Views:
    2,421
  4. =?Utf-8?B?UGV0ZXI=?=

    Wrong language displayed when using ResourceManager

    =?Utf-8?B?UGV0ZXI=?=, Feb 18, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    900
    =?Utf-8?B?UGV0ZXI=?=
    Feb 18, 2005
  5. Matthew
    Replies:
    7
    Views:
    665
    Priscilla Walmsley
    Jan 7, 2005
Loading...

Share This Page