LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   gcc 3.4.2 and template issue (http://www.linuxquestions.org/questions/programming-9/gcc-3-4-2-and-template-issue-313849/)

ahwkong 04-16-2005 09:45 AM

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

Hivemind 04-16-2005 01:18 PM

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


All times are GMT -5. The time now is 06:00 PM.