Hi, I'm sure I've typed something wrong but when trying to complied this example, I get:
1>c:\users\terry\onedrive\documents\tech stuff\programming\c++\ex10_07\ex10_07\function_obj ect.h(8): error C2143: syntax error: missing ';' before '('
I've copied the code from the download in case there was something I just wasn't seeing but get the same error.
Any ideas anyone? Is it a difference between versions? I'm using VS 2017 Community (all updates applied) on Win 10.
The code for function_object. h is:
Code:
#pragma once
#include <functional>
template <class T> class is_negative : public std::unary_function<T , bool>
{
public:
result_type operator()(argument_type& value)
{
return value < 0;
}
};
It's being called like this:
Code:
// Process integers
std::list<int> numbers;
cout << "Enter non-zero integers separated by spaces. Enter 0 to end."
<< endl;
loadList(numbers);
cout << "The list contains:" << endl;
listAll(numbers);
numbers.remove_if(is_negative<int>());
cout << "After applying remove_if() the list contains:" << endl;
listAll(numbers);
UPDATE: Strangely, all works fine if I replace the base template class references as so:
Code:
template <class T> class is_negative
{
public:
bool operator()(const T& value)
{
return value < 0;
}
};