Author |
Message |
canmovie
|
Posted: 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

|
|
 |
y4y
|
Posted: 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

|
Posted: 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

|
Posted: 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. |
|
|
|
|
 |
|