static_cast<class<T>> error

I'm obviously very new to c++. I have a class Vector2<T> and I'm trying to cast a void pointer to it using a static_cast. However the ide(xcode) seems to not accept the syntax I am using.

I get this error:
Expected '>'

Here's the code:
 
delete static_cast<Vector2<float>*>(value); //value is of type void* 


Any help would be appreciated.
Can you please supply the full error.

Also,
1. Why have you written your own vector class?
2. Why are you trying to cast to a Vector2<Float>* ?
3. Why are you trying to delete the result of the cast?
Sorry I've fixed the mistake. I had defined a constant with the same name so there was a conflict and the complier got confused.
Use

delete reinterpret_cast<Vector2<float> *>( value );

provided that Vector2 is a user-defined template class.

Or


delete reinterpret_cast<std::vector<float> *>( value );

if std::vector is used.
But even so, I'd be very concerned that you need to cast before you do the delete. This indicates code smell to me: http://en.wikipedia.org/wiki/Code_smell
Okay, I'm using void pointers because I need an vector of attributes that can be of many types float, int, double, Vector2(custom class), Matrix ... etc. It seems to me that void pointers are the best way to do this. The reason I need to cast before deleting is that one simply cannot delete a void pointer. Please tell me if there are any glaring weakness in this design. Thanks!
You say you need a vector of attributes that can be of different types. But unless you know the type of it you cannot utilise it appropriately. At some point you have to know the type, so you shouldn't need to cast.

e.g
1
2
3
4
5
6
7
vector<void*> attributes;

attributes.push_back(/* float */);
attributes.push_back(/* string */);

// Now I need to know that attributes[0] is a float to use it


If you truly need to store different types of data, then you should use something like: http://www.boost.org/doc/libs/1_52_0/doc/html/any/s02.html

You haven't provided a problem that I would say warrants the use of an any container. The use of these is highly discouraged because of the complexity involved.




I don't actually have a vector void. I have a vector<container> where container is a class which contains a type variable and a void pointer. But even if I know the type, don't I still have to cast the pointer back to the original type to use the data.
Think higher level than this. Why do you need to have different attribute types? Isn't there a better way for me to store this information?

Only once in 10 years of professional C++ have I actually had a valid use for this kind of solution.
Topic archived. No new replies allowed.