473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

question about templates

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

Jul 23 '05 #1
1 1533
pp****@gmail.com 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
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fran Cotton | last post by:
Hi, I'd greatly appreciate it if someone could cast light on my problem - I can't seem to find any reference to it anywhere. Consider the following XML: <paragraph> I am...
4
by: Karsten Weinert | last post by:
Hello, can someone please explain to me why the one stylesheet given below works, but the other not? <!-- This stylesheet works --> <?xml version="1.0"?> <xsl:stylesheet...
1
by: Scott | last post by:
The following is the XML I have to work with. Below is the question <Table0> <CaseID>102114</CaseID> <CaseNumber>1</CaseNumber> <DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened>...
1
by: Markus Seeger | last post by:
Hi, I'm writing a commandline argument parser that can handle switches by using some techniques similar to the Qt slot mechanism. example: // inheritance method (what I'm trying at the...
3
by: Dennis Pais | last post by:
Here's a piece of code that I found in C++ Primer by Stan Lippman ! ------------------------------------------------- template<typename T, int size> T min(T (&r_array) ) { Type min_value =...
1
by: Alfonso Morra | last post by:
if I have a class template declared as ff: (BTW is this a partial specialization? - I think it is) template <typename T1, myenum_1 e1=OK, my_enum_2=NONE> class A { public: A(); virtual...
0
by: Piper707 | last post by:
I need help with using a general template which would process all tags other than the ones for which specific templates have been written. My XML looks like this: <ITEMS>...
5
by: Support | last post by:
Hello: I have the following code that currently needs to go in every page. QUESTION 1) Can Page_Preinit go somewhere else more global like Global.asax so that I dont have to copy this code in...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
3
by: davisford | last post by:
Hi, If I have something like this: <parents> <parent name="foo"> <children> <child>fred</child> <child>barney</child> <child>wilma</child>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.