472,117 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,117 software developers and data experts.

compile error " instantiated from here"

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 =
__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>
, _Tp = double, _BinaryOperation = do_std_dev<int>]':

.../stddev.cpp:215: instantiated from here
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;
}

Feb 13 '06 #1
2 8707
> [...]
../stddev.cpp:215: warning: converting to 'int' from 'double'
[...]


I recommend you provide a complete minimal example without any
conversion-from-int-to-double-issue. Focus e.g. on int first. As far
as I see the conversion is of no relevance for the
standard-deviation-feature you want to have. Maybe clearing the
conversion-issue already leads to a working program.

Feb 13 '06 #2
In article <11**********************@g14g2000cwa.googlegroups .com>,
ke*********@gmail.com wrote:
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_nu
meric.h:
In function '_Tp std::accumulate(_InputIterator, _InputIterator, _Tp,
_BinaryOperation) [with _InputIterator =
__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>
, _Tp = double, _BinaryOperation = do_std_dev<int>]':

../stddev.cpp:215: instantiated from here
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;
}


Look at the template for accumulate and remember that "0.0" is a double
whereas "0" is an int. What type does accumulate return?

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Alexander Bartzas | last post: by
2 posts views Thread by Happy Li | last post: by
1 post views Thread by ken.carlino | last post: by
reply views Thread by yyuan168a | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.