P
PengYu.UT
Hi All,
I want to use scrJ_minus_O as the function to fill in the array "a" in
population_decomposition. But the g++ compiler always says the line "
pop_dec(scrJ_minus_O<double>(.5));" is wrong.
main.cc: In function `int main(int, char **)':
main.cc:39: no matching function for call to `pop_dec
(scrJ_minus_O<double>)'
Would you please tell me how I should change line 39? Thanks!
Best wishes,
Peng
#include <iostream>
#include <functional>
#include <cmath>
template <class _Tp>
class scrJ_minus_O : public binary_function<_Tp, _Tp, _Tp>{
public:
scrJ_minus_O(_Tp sigma) : _sigma(sigma) {};
_Tp operator()(const _Tp f, const _Tp g){
if((f * f + g * g) < _sigma * _sigma)
return 1. / (M_PI * _sigma * _sigma);
else
return 0.;
}
private:
_Tp _sigma;
};
template <class _Tp, class _Generator>
class population_decomposition {
public:
population_decomposition(const _Generator& generator) :
_generator(generator) {
for(int i = 0; i < 10; i ++){
a = _generator(.1 * i, .1 * i);
}
};
_Tp a[10];
private:
_Generator _generator;
};
template <class _Tp, class _Generator>
inline population_decomposition<_Tp, _Generator>
pop_dec(const _Generator& generator){
return population_decomposition<_Tp,_Generator>(generator);
}
main(int argc, char *argv[]){
pop_dec(scrJ_minus_O<double>(.5));
}
I want to use scrJ_minus_O as the function to fill in the array "a" in
population_decomposition. But the g++ compiler always says the line "
pop_dec(scrJ_minus_O<double>(.5));" is wrong.
main.cc: In function `int main(int, char **)':
main.cc:39: no matching function for call to `pop_dec
(scrJ_minus_O<double>)'
Would you please tell me how I should change line 39? Thanks!
Best wishes,
Peng
#include <iostream>
#include <functional>
#include <cmath>
template <class _Tp>
class scrJ_minus_O : public binary_function<_Tp, _Tp, _Tp>{
public:
scrJ_minus_O(_Tp sigma) : _sigma(sigma) {};
_Tp operator()(const _Tp f, const _Tp g){
if((f * f + g * g) < _sigma * _sigma)
return 1. / (M_PI * _sigma * _sigma);
else
return 0.;
}
private:
_Tp _sigma;
};
template <class _Tp, class _Generator>
class population_decomposition {
public:
population_decomposition(const _Generator& generator) :
_generator(generator) {
for(int i = 0; i < 10; i ++){
a = _generator(.1 * i, .1 * i);
}
};
_Tp a[10];
private:
_Generator _generator;
};
template <class _Tp, class _Generator>
inline population_decomposition<_Tp, _Generator>
pop_dec(const _Generator& generator){
return population_decomposition<_Tp,_Generator>(generator);
}
main(int argc, char *argv[]){
pop_dec(scrJ_minus_O<double>(.5));
}