Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

what's wrong with this?

Name: Anonymous 2006-05-19 18:41

#include<iostream>

using namespace std;

struct db : public unary_function<int, int> {
  int operator()(const int& x) { return 2 * x; }
};

void f(int x, unary_function<int, int> t) {
  cout << t(x) << endl;
}

int main() {
  f(2, db());
  return 0;
}


Gives me a compile error:

test.cpp: In function ‘void f(int, std::unary_function<int, int>)’:
test.cpp:11: error: no match for call to ‘(std::unary_function<int, int>) (int&)’

Name: Anonymous 2006-05-20 0:03

>>6
learn C++ please, structs are just classes with everything public by default.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List