Well, that is almost what i want.
I need to convert a const float value not a variable. 'Cos i can't make a void* to hold a address and later on get the value of the address.
so i need :
1 2 3 4 5 6 7
void* convertV (constfloat & a) {
return (/*WHAT*/);
}
float convertF (void* a) {
return *static_cast<float*>(a);
}
Working with void pointers is bad because you have all the problems associated with pointers in addition to the lack of type safety. You are basically throwing away all the mechanisms in place to ensure type safety and adding in the problems of pointers on top of it. It is extremely rare to actually need to use a void pointer in C++.
An alternative is a typesafe wrapper like boost::any, but it is still uncommon to need this. Why do you need to store objects of different types in the same container?
I'm a C# and Java programmer. So i can use Object class.
And now i'm trying to learn C++. And i want to make a simple program that accepts : IADD, 1, 1FADD, 0.2f, 12.45f
And it needs to print in the screen the result. When IADD is integer addition and FADD is float addition. So i need a type that can hold integers and floats and later chars