Find the answer to your Linux question:
Results 1 to 4 of 4
Hello all, I'm a newbrie to g++ (in fact new to programming in linux environment). I'm trying to port some code, but a get an error during compilation. Any ideas ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2006
    Location
    UK
    Posts
    5

    Question g++ template code won't compile


    Hello all,

    I'm a newbrie to g++ (in fact new to programming in linux environment).
    I'm trying to port some code, but a get an error during compilation.

    Any ideas ?

    Regards
    Dave

    PHP Code:
    #include <vector>
     
    using namespace std;
     
    template <typename T>
    class 
    ptrvector : public vector<T*>
    {
    public:
     ~
    ptrvector()
     {
      
    vector<T*>::iterator i;
     }
    };
     
    int mainint argccharargv[] ) 
    {
     return 
    0;

    g++ test.cpp -o test.exe
    test.cpp: In destructor 'ptrvector<T>::~ptrvector()':
    test.cpp:13: error: expected `;' before 'i'
    make: *** [test.o] Error 1

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2005
    Location
    Hell
    Posts
    514
    maybe
    Code:
    #include <vector>
     
    using namespace std;
     
    template <typename T>
    class ptrvector : public vector<T*>
    {
    public:
     ~ptrvector()
     {
      typename vector<T*>::iterator i;
     }
    };
     
    int main( int argc, char* argv[] ) 
    {
     return 0;
    }

  3. #3
    Just Joined!
    Join Date
    Apr 2006
    Location
    UK
    Posts
    5
    Quote Originally Posted by spoon!
    maybe
    Code:
    #include <vector>
     
    using namespace std;
     
    template <typename T>
    class ptrvector : public vector<T*>
    {
    public:
     ~ptrvector()
     {
      typename vector<T*>::iterator i;
     }
    };
     
    int main( int argc, char* argv[] ) 
    {
     return 0;
    }
    Spoon, thanks for the response, but its no good.

    I'm not trying to declare a type, but an interator to a vector template which has type T*.

    BTW: I'm using g++ 4.0.0.

    Regards
    Dave

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Apr 2006
    Location
    UK
    Posts
    5
    Spoon,

    Sorry you were right (I suffered from a bit of finger trouble or brain trouble), 'typename' was the answer.

    Many thanks.

    Regards
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •