Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How can I have an interchangeable datatype?
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
canmovie




PostPosted: Fri Nov 23, 2012 10:52 am   Post subject: How can I have an interchangeable datatype?

I've used ints instead of floats for most of my variables in my program, and now I have to search for every int variable, and turn it into a float.
How can I prevent this from happening again?
I've thought about declaring everything as floats in the beginning if I think I may eventually turn them into floats later on, but is there another way?
For example, can I somehow make the datatype a variable that i can change from int to float if I want to?

What can I do while writing my program in the beginning to easily be able to change datatypes from int to float later on?

Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
y4y




PostPosted: Fri Nov 23, 2012 12:49 pm   Post subject: RE:How can I have an interchangeable datatype?

can't say i have an exact solution, but for your situation i would simply use a define multivar in headers/top of your code and then simply switch from int to float when needed.

or you could create a class that can process/contain both int and floats.

also idk much about templates but this is possible in some way ( maybe using templates?) as some languages implement it.
Insectoid




PostPosted: Fri Nov 23, 2012 1:52 pm   Post subject: RE:How can I have an interchangeable datatype?

Did you really do this? Or did you make this up because you had a homework question asking you how to prevent this happening in the first place?
md




PostPosted: Fri Nov 23, 2012 3:54 pm   Post subject: RE:How can I have an interchangeable datatype?

No matter the case there is no reason to create three separate threads with the same (rather horrible) first post. Don't do it again.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: