|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
relatively new to C++... a little template help?
#include<iostream.h>
#include<conio.h> template<class T> void square(T x) { return(x * x); } void main() { char letter = 'A'; int integer= 5; double money= 2.25; cout<<"The square of "<<letter<<" is "<<square(letter)<<endl; cout<<"The square of "<<integer<<" is "<<square(integer)<<endl; cout<<"The square of "<<money<<" is "<<square(money)<<endl; getch(); } I receive the error: error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion) on each of my cout statements. Thanks in advance! |
|
#2
|
|||
|
|||
|
answer
you have to include the pre processor command
include <math.h> in order to peform the math functions for squaring. |
|
#3
|
|||
|
|||
|
your square function is of type void.
while at the same time, the function is trying to return a value (i'm assuming) of type T. just change void to T. that should do the trick. |
|
#4
|
|||
|
|||
|
This is a Visual Basic forum, not a C++ forum.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#5
|
|||
|
|||
|
comment
Yes I agree with facecheekwall, your template function has a void type and you set your function to return a value it should not be void it should be I think in this case T. I agree with that, it should do it for you
Sura |
|
#6
|
|||
|
|||
|
sura, you didn't read my post. If you're looking for a C++ developer forum try www.devshed.com
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > relatively new to C++... a little template help? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|