This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
gcc-3.1 problem
- From: "Tony, Zhou Jingtao" <zhoujing at figaro dot ddns dot comp dot nus dot edu dot sg>
- To: gcc at gnu dot org, <gcc at gcc dot gnu dot org>
- Date: Wed, 26 Jun 2002 12:22:19 +0800 (SGT)
- Subject: gcc-3.1 problem
- Reply-to: zhoujing at comp dot nus dot edu dot sg
Doesn't the "g++" of "gcc-3.1" support "default argument"? I got an error when compiling the following program with it, while it ran fine with "gcc-3.0.4".
----------
StrTok.h:
----------
#ifndef __STRINGTOKENIZER_H__
#define __STRINGTOKENIZER_H__
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class StrTok
{
public:
StrTok (string s, string delim = " ");
inline bool hasMoreTokens() const {return (!sVec.empty ());}
inline int countTokens() const {return sVec.size();}
string nextToken ();
private:
vector<string> sVec;
};
#endif
------------
StrTok.cpp:
------------
#include <StrTok.h>
StrTok::StrTok(string s, string delim = " ")
{
// break s into many tokens with d
// and store them into sVec
string d = "\t\n" + delim;
string::size_type pos = s.find_first_not_of(d);
string::size_type prePos = pos;
while ((pos = s.find_first_of(d, pos)) != string::npos) {
sVec.push_back(s.substr(prePos, pos - prePos));
pos = s.find_first_not_of(d, pos);
prePos = pos;
}
if (pos > prePos) {
sVec.push_back(s.substr(prePos, pos - prePos));
}
}
string StrTok::nextToken()
{
if (hasMoreTokens()) {
string t = sVec[0];
sVec.erase(sVec.begin(), sVec.begin() + 1);
return t;
} else
return "";
}
----------
Makefile:
----------
CXX=g++
CXXFLAGS=-Wall -O2
prefix=/usr/local
object=StrTok.o
dobj=libStrTok.so.0.0.1
sobj=libStrTok.a
all: $(object) dynamic static
$(object): %.o:%.cpp
$(CXX) -c $^ $(CXXFLAGS) -I.
dynamic:
$(CXX) $(object) -o $(dobj) -shared
static:
ar r libStrTok.a StrTok.o
ranlib libStrTok.a
install:
install -c $(dobj) $(prefix)/lib
-rm $(prefix)/lib/libStrTok.so -f
ln $(prefix)/lib/$(dobj) $(prefix)/lib/libStrTok.so -s
install -c $(sobj) $(prefix)/lib
install -c StrTok.h $(prefix)/include
chmod 644 $(prefix)/lib/$(sobj)
chmod 644 $(prefix)/include/StrTok.h
clean:
rm -f $(object) $(dobj) $(sobj)
.PHONY: all dynamic static clean install
-----------------------------------------
Got the following error when compiling:
-----------------------------------------
g++ -c StrTok.cpp -Wall -O2 -I.
StrTok.cpp:23: default argument given for parameter 2 of `
StrTok::StrTok(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > = " ")'
StrTok.h:32: after previous specification in `
StrTok::StrTok(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > = " ")'
make: *** [StrTok.o] Error 1
Can you please help? Thanks in advance.
--
Truely, Madly, Deeply
Tony
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.comp.nus.edu.sg/~zhoujing
Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.