LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2005, 09:45 AM   #1
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
gcc 3.4.2 and template issue


I want to compile the following code segment:
Code:
namespace VE {

template <class T> class tset :public std::set<T>
{

public:

    T* Find(const T& key){
        iterator i = find(key);
        return i == end() ? 0 : &(*i);
    }

    const T* Find(const T& key) const{
        const_iterator i = find(key);
        return i == end() ? 0 : &(*i);
    }
};

}
This was originally developed in VC and now i am trying to port it to gcc.

However gcc produced these error messages:

Code:
tset.h: In member function `const T* VE::tset<S, T>::Find(const S&):
tset.h:39: error: expected `;' before "i"
tset.h:40: error: `i' undeclared (first use this function)
tset.h:40: error: (Each undeclared identifier is reported only once for each function it appears in.)
tset.h: In member function `const T* VE::tset<S, T>::Find(const S&) const':
tset.h:45: error: `const_iterator' undeclared (first use this function)
tset.h:45: error: expected `;' before "i"
tset.h:46: error: `i' undeclared (first use this function)

Any idea on how to solve this problem is appreciated
 
Old 04-16-2005, 01:18 PM   #2
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
This code compiles using gcc 3.3.3. It may work for your version too, but you may encounter problems because the gcc 3.4.x series is more standard compliant than gcc 3.3.* is and will balk one some invalid code that earlier versions accepted.

Code:
#include <set>

namespace VE {

template<typename T>
class tset : public std::set<T>
{

public:

   T* Find(const T& key)
   {
      typename tset::iterator i = find(key);
      return i == end() ? 0 : &(*i);
   }

   const T* Find(const T& key) const
   {
      typename tset::const_iterator i = find(key);
      return i == end() ? 0 : &(*i);
   }
};

}

int
main()
{
   VE::tset<int> myset;
   
   return 0;
}
Hope this helps

Last edited by Hivemind; 04-16-2005 at 01:23 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help installing TeTeX. GCC issue? Erik_the_Red Linux - Software 3 10-09-2005 10:38 AM
Template class with a template member... Nicholas Bishop Programming 3 02-21-2005 08:27 PM
GCC 3.3.2-6 Installation Issue Shoal Linux - Software 1 11-02-2004 07:24 PM
Slackware current + gcc issue vexer Slackware 2 08-11-2003 12:05 PM
problem in template function. compiles in vc++ not in gcc 3.0.4 cybercop12us Programming 4 12-12-2002 01:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration