Добрый день.
Имеем следующий код:
| Код | #include <map> #include <functional>
#define SIZE 100
class test { public: int buf[SIZE];
struct my_less : std::binary_function <const int&, const int&, bool> { result_type operator() (first_argument_type arg1, second_argument_type arg2) { return buf[arg1] > buf[arg2]; } }; typedef std::map<int, int, my_less> mymap;
mymap m;
test() { // Заполняем buf }
void add(int a, int b) { m[a] = b; } };
int main(void) { test m; return 0; }
|
При компиляции получаю ошибку
| Код | $ g++ test.cpp test.cpp: In member function ‘bool test::my_less::operator()(const int&, const int&)’: test.cpp:14: ошибка: invalid use of nonstatic data member ‘test::buf’ test.cpp:14: ошибка: invalid use of nonstatic data member ‘test::buf’
|
Пытался сделать buf статичным членом, но тогда не получается его юзать в других функциях класса. Ну это по причине кривых рук. Подскажите, как это правильно реализовать. |