not1 function Adapter problem

The following program works on g++ 4.4 when IsOdd is a struct and does not compile when IsOdd is a class. The error message (partial) is
/usr/include/c++/4.4/bits/stl_function.h:102: error: ‘typedef int std::unary_function<int, bool>::argument_type’ is inaccessible

Code:


#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;

class IsOdd : unary_function<int,bool> {
public:
bool const operator() (const int& x) const {return x%2==1;}

};

int main() {
vector<int> inVector;

for( int i = 1; i <= 11; ++i ) {
inVector.push_back(i);
}

int cx;
cx = count_if ( inVector.begin(), inVector.end(), not1(IsOdd()));
cout << "There are " << cx << " elements with even values.\n";

return 0;
}


Thanks for any help.
class IsOdd is inheriting unary_function privately
Bazzy!

Thank you. It should have been obvious to me.
Topic archived. No new replies allowed.