Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > compile error " instantiated from here"

Reply
Thread Tools

compile error " instantiated from here"

 
 
ken.carlino@gmail.com
Guest
Posts: n/a
 
      02-13-2006
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;
}

 
Reply With Quote
 
 
 
 
Marco Wahl
Guest
Posts: n/a
 
      02-13-2006
> [...]
> ../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.

 
Reply With Quote
 
 
 
 
Daniel T.
Guest
Posts: n/a
 
      02-13-2006
In article < .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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
How to solve the error "The local variable may not have been instantiated"? Shawn Java 8 09-28-2006 03:28 PM
"instantiated from here" compile error when using template yinglcs@gmail.com C++ 2 02-19-2006 05:22 AM
compile error " instantiated from here" ken.carlino@gmail.com C++ 1 02-13-2006 12:30 PM
View instantiated RAM by address in sim dwerdna VHDL 8 03-23-2005 03:53 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57