Problem with libstdc++-v3.0.96 and #include <functional>
POKAM Christian
c.pokam@worldonline.de
Sun Feb 3 22:10:00 GMT 2002
When compiling this small file (MemFun.cpp) with the latest
libstdc++v3.0.96, I get this error :
MemFun.cpp:29: `compose1' undeclared (first use this function)
Is compose1 not part of <functional>?
gcc -v:
Reading specs from
/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.3/specs
Configured with: ../gcc-3.0.3/configure --prefix=/usr/local/gcc3
--enable-language
s=c,c++ --enable-threads=posix
Thread model: posix
gcc version 3.0.3
//MemFun.cpp
#include "NumStringGen.h"
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <functional>
using namespace std;
int main() {
const int sz = 9;
vector<string> vs(sz);
// Fill it with random number strings:
generate(vs.begin(), vs.end(), NumStringGen());
copy(vs.begin(), vs.end(),
ostream_iterator<string>(cout, "\t"));
cout << endl;
vector<double> vd;
transform(vs.begin(), vs.end(), back_inserter(vd),
compose1(ptr_fun(atof),
mem_fun_ref(&string::c_str)));
copy(vd.begin(), vd.end(),
ostream_iterator<double>(cout, "\t"));
cout << endl;
} ///:~
--------------------------------------------
//NumStringGen.h
#ifndef NUMSTRINGGEN_H
#define NUMSTRINGGEN_H
#include <string>
#include <cstdlib>
#include <ctime>
class NumStringGen {
const int sz; // Number of digits to make
public:
NumStringGen(int ssz = 5) : sz(ssz) {
std::srand(std::time(0));
}
std::string operator()() {
static char n[] = "0123456789";
const int nsz = 10;
std::string r(sz, ' ');
for(int i = 0; i < sz; i++)
if(i == sz/2)
r[i] = '.'; // Insert a decimal point
else
r[i] = n[std::rand() % nsz];
return r;
}
};
#endif // NUMSTRINGGEN_H ///:~
More information about the Gcc-help
mailing list