Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > question about templates

Reply
Thread Tools

question about templates

 
 
pplppp@gmail.com
Guest
Posts: n/a
 
      06-16-2005
Hi,
I have a simple program which I wrote and compiled on SCO Unixware
7.1.1 (compiler is CC) with SGI STL and it compiled and worked fine.
Now I'm using GNU GCC 4.0.0 on linux, with the GCC implementation of
STL and I have some trouble trying compile the same code:
the following is a segemnt of my program:


[StringUtil.h]
....
#include <string>
using namespace std;
....
template<typename T>basic_string<T> trimCopy(const basic_string<T>&
str);
....

[StringUtil.cpp]
....
template<typename T>basic_string<T> trimCopy(const basic_string<T>&
str)
{
basic_string<T>::size_type front = str.find_first_not_of(" \t\n");
// line 97
basic_string<T>::size_type end = str.find_last_not_of(" \t\n"); //
line 98
return str.substr(front, end-front+1); // line 99
}
....

when I try to compile the program, g++ gives me an error

/usr/local/bin/g++ -g -frepo -O -I. -I/usr/local/include -c
StringUtil.cpp
StringUtil.cpp: In function 'std::basic_string<T,
std::char_traits<_CharT>, std::allocator<_CharT> > trimCopy(const
std::basic_string<T, std::char_traits<_CharT>, std::allocator<_CharT>
>&)':

StringUtil.cpp:97: error: expected `;' before 'front'
StringUtil.cpp:98: error: expected `;' before 'end'
StringUtil.cpp:99: error: 'front' was not declared in this scope
StringUtil.cpp:99: error: 'end' was not declared in this scope


I would like to know why I'm getting this error, since with the SGI STL
implementation and SCO Unixware CC compiler I have no problem with the
same piece of code. Any help is appreciated

Thanks in advance

newbie

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-16-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have a simple program which I wrote and compiled on SCO Unixware
> 7.1.1 (compiler is CC) with SGI STL and it compiled and worked fine.
> Now I'm using GNU GCC 4.0.0 on linux, with the GCC implementation of
> STL and I have some trouble trying compile the same code:
> the following is a segemnt of my program:
>
>
> [StringUtil.h]
> ...
> #include <string>
> using namespace std;
> ...
> template<typename T>basic_string<T> trimCopy(const basic_string<T>&
> str);
> ...
>
> [StringUtil.cpp]
> ...
> template<typename T>basic_string<T> trimCopy(const basic_string<T>&
> str)
> {


Add keyword 'typename' here

> basic_string<T>::size_type front = str.find_first_not_of(" \t\n");
> // line 97


Add keyword 'typename' here too

> basic_string<T>::size_type end = str.find_last_not_of(" \t\n"); //
> line 98
> return str.substr(front, end-front+1); // line 99
> }
> ...


Both 'front' and 'end' are declared to have a _dependent_type_. It is
dependent on the meaning of 'T'. To help the compiler decide what you
mean there, you need to say

typename basic_string<T>::size_type front ...

>
> when I try to compile the program, g++ gives me an error
>
> /usr/local/bin/g++ -g -frepo -O -I. -I/usr/local/include -c
> StringUtil.cpp
> StringUtil.cpp: In function 'std::basic_string<T,
> std::char_traits<_CharT>, std::allocator<_CharT> > trimCopy(const
> std::basic_string<T, std::char_traits<_CharT>, std::allocator<_CharT>
>
>>&)':

>
> StringUtil.cpp:97: error: expected `;' before 'front'
> StringUtil.cpp:98: error: expected `;' before 'end'
> StringUtil.cpp:99: error: 'front' was not declared in this scope
> StringUtil.cpp:99: error: 'end' was not declared in this scope
>
>
> I would like to know why I'm getting this error, since with the SGI STL
> implementation and SCO Unixware CC compiler I have no problem with the
> same piece of code. Any help is appreciated


V
 
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
how to Specializations of function Templates or Overloading Function templates with Templates ? recover C++ 2 07-25-2006 02:55 AM
Monster Templates - Question about Submitting Templates Fred HTML 1 09-26-2005 01:09 AM
Templates within templates Tom McCallum C++ 2 08-04-2004 04:44 PM
Templates templates templates JKop C++ 3 07-21-2004 11:44 AM
using templates in templates John Harrison C++ 8 07-31-2003 12:00 PM



Advertisments