K
ken.carlino
Hi,
I have the following compile error instantiated from here, I appreciate
if someone can help me find out why?
g++ -O0 -g3 -Wall -c -fmessage-length=0 -ostddev.o ../stddev.cpp
.../stddev.cpp: In member function 'int
StatUtils::std_dev(std::vector<int, std::allocator<int> >&, int,
int)':
.../stddev.cpp:206: warning: converting to 'int' from 'double'
.../stddev.cpp:215: warning: converting to 'int' from 'double'
.../stddev.cpp:218: warning: converting to 'int' from 'double'
.../stddev.cpp: In member function 'int
StatUtils::mean(std::vector<int, std::allocator<int> >&, int, int)':
.../stddev.cpp:232: warning: converting to 'int' from 'double'
/usr/lib/gcc/i386-redhat-linux/4.0.1/../../../../include/c++/4.0.1/bits/stl_numeric.h:
In function '_Tp std::accumulate(_InputIterator, _InputIterator, _Tp,
_BinaryOperation) [with _InputIterator =
Here is the code :
template< class T1> class do_std_dev : public binary_function<T1, T1,
T1>
{
public:
do_std_dev(T1 mean): _mean(mean) { }
T1 operator() (T1 initial, T1 element) {
T1 x = element - _mean;
initial = initial + (x * x);
return initial;
}
private:
T1 _mean;
};
int StatUtils::std_dev( vector<int>& v, int start, int end)
{
int stdDev = 0.0;
int mean2 = mean(v, start, end);
vector<int>::iterator startIter = v.begin();
vector<int>::iterator endIter = v.begin();
startIter += start;
endIter += end;
// this is line 215 of stddev.cpp:
int stdDevSum = accumulate (startIter, endIter, 0.0,
do_std_dev<int>(mean2));
return stdDevSum;
}
I have the following compile error instantiated from here, I appreciate
if someone can help me find out why?
g++ -O0 -g3 -Wall -c -fmessage-length=0 -ostddev.o ../stddev.cpp
.../stddev.cpp: In member function 'int
StatUtils::std_dev(std::vector<int, std::allocator<int> >&, int,
int)':
.../stddev.cpp:206: warning: converting to 'int' from 'double'
.../stddev.cpp:215: warning: converting to 'int' from 'double'
.../stddev.cpp:218: warning: converting to 'int' from 'double'
.../stddev.cpp: In member function 'int
StatUtils::mean(std::vector<int, std::allocator<int> >&, int, int)':
.../stddev.cpp:232: warning: converting to 'int' from 'double'
/usr/lib/gcc/i386-redhat-linux/4.0.1/../../../../include/c++/4.0.1/bits/stl_numeric.h:
In function '_Tp std::accumulate(_InputIterator, _InputIterator, _Tp,
_BinaryOperation) [with _InputIterator =
.../stddev.cpp:215: instantiated from here__gnu_cxx::__normal_iterator said:, _Tp = double, _BinaryOperation = do_std_dev<int>]':
Here is the code :
template< class T1> class do_std_dev : public binary_function<T1, T1,
T1>
{
public:
do_std_dev(T1 mean): _mean(mean) { }
T1 operator() (T1 initial, T1 element) {
T1 x = element - _mean;
initial = initial + (x * x);
return initial;
}
private:
T1 _mean;
};
int StatUtils::std_dev( vector<int>& v, int start, int end)
{
int stdDev = 0.0;
int mean2 = mean(v, start, end);
vector<int>::iterator startIter = v.begin();
vector<int>::iterator endIter = v.begin();
startIter += start;
endIter += end;
// this is line 215 of stddev.cpp:
int stdDevSum = accumulate (startIter, endIter, 0.0,
do_std_dev<int>(mean2));
return stdDevSum;
}