A
Alex Buell
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
template <typename T>
class LessThan
{
private:
T comp;
public:
LessThan(T val) : comp(val) {}
void setComp(const T& val) { comp = val; }
T getComp(void) { return comp; } const
bool operator()(const T& value) { return value < comp; }
};
int main()
{
double darr[10] = { 234.4, 11.1, 22.2, 500.0, 50.0, 11.1, 12.1,
600.6, 99.9, 0.0 }; vector<double> v2(darr, darr + 10);
double dal = 100.0;
LessThan<double> lt2(dal);
int count1 = count_if(v2.begin(), v2.begin(), lt2);
cout << "There are " << count1 << " values less than " << dal
<< endl;
return 0;
}
Expected output should have been "There are 7 values less than 100",
but it actually comes up with: "There are 0 values less than 100". Why?
I'm using GCC 3.4.4 on Linux
Thanks
#include <algorithm>
#include <iostream>
using namespace std;
template <typename T>
class LessThan
{
private:
T comp;
public:
LessThan(T val) : comp(val) {}
void setComp(const T& val) { comp = val; }
T getComp(void) { return comp; } const
bool operator()(const T& value) { return value < comp; }
};
int main()
{
double darr[10] = { 234.4, 11.1, 22.2, 500.0, 50.0, 11.1, 12.1,
600.6, 99.9, 0.0 }; vector<double> v2(darr, darr + 10);
double dal = 100.0;
LessThan<double> lt2(dal);
int count1 = count_if(v2.begin(), v2.begin(), lt2);
cout << "There are " << count1 << " values less than " << dal
<< endl;
return 0;
}
Expected output should have been "There are 7 values less than 100",
but it actually comes up with: "There are 0 values less than 100". Why?
I'm using GCC 3.4.4 on Linux
Thanks