TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BOB STOUT
from: SUNIR SHAH
date: 1997-07-17 22:55:00
subject: Rtti

To: Bob Stout
Subject: RTTI
I'm not exactly an expert on templates on C++ or anything, but from the
sum total of, um, 12 hours so far I've spend learning C++...
Man is that a flashback to when I was 13 and starting out in the C_ECHO. ;)
If it takes me five years to master C++ I'm going to go nuts.
 BS> the % operator. In C, I have to make type-specific 
 BS> versions, so the function which works with doubles simply 
 BS> uses fmod() instead of %. However, I'm kinda lost when it 
 BS> comes to writing a template-based equivalent which will 
 BS> need to either use the % operator or call fmod() depending 
 BS> on the type of its arguments and return value.
Why can't you put a constraint on the template that the class T has 
verloaded
the % operator to work with it?
So if you had a float value to play with, you can overload the % operator
to fmod().
Or do you mean just default types?  Like an actual float and double?
You can't overload operators for those, IIRC.. but you can create multiple
functions.  If you can call functions within a template (I'm sure you can),
why not just call a function MyMod( foo, bar ) within the template and
overload MyMod for the various types?
That keeps the template generic while providing the flexibility you need.
SS
--- Maximus 3.01
---------------
* Origin: BitByters BBS, Rockland ON, Can. (613)446-7773 v34, (1:163/215)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.