Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old July 28th, 2004, 06:40 PM
twopecker twopecker is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 148 twopecker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 48 m 59 sec
Reputation Power: 5
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!

Reply With Quote
  #2  
Old July 29th, 2004, 04:34 PM
motoxeryz125 motoxeryz125 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 83 motoxeryz125 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 3 m 42 sec
Reputation Power: 5
answer

you have to include the pre processor command
include <math.h>
in order to peform the math functions for squaring.

Reply With Quote
  #3  
Old October 6th, 2004, 04:40 PM
faceCHEEKwall faceCHEEKwall is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 faceCHEEKwall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old October 6th, 2004, 09:40 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 51 m 25 sec
Reputation Power: 180
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

Reply With Quote
  #5  
Old October 7th, 2004, 11:43 AM
sura sura is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 sura User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #6  
Old October 7th, 2004, 09:49 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 51 m 25 sec
Reputation Power: 180
sura, you didn't read my post. If you're looking for a C++ developer forum try www.devshed.com

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > relatively new to C++... a little template help?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway