   [C++] Is casting unused template parameters to void dangerous?
class Foo{};template <class A, class B>class Bar: public Foo{public:    A a;    B b;};template <class B>bool function(Foo *foo, B b){    Bar *bar = static_cast<Bar<void, B> >(foo); // casting A to void    return (b == bar.b); // we don't use bar.a}void main(){    Bar<int, float> bar;    bar.a = 5;    bar.b = 6.7;    Foo *foo = &bar; // actually, we have a std::vector of Foo, this is a simplification    return function(&bar);}Is it, in the above example, alright to cast to unknown and unused template parameter of Bar to a void? Or what would be more appropriate?Thanks   
  That will probably blow up messily if it even compiles. What a better approach would be depends on what the actual problem you're dealing with is.   ;Quote:Original post by SiCraneThat will probably blow up messily if it even compiles. What a better approach would be depends on what the actual problem you're dealing with is.Well, it has worked so far (EDIT: okay, maybe it didn't...), but I too believe this is explode-able...The actual problem is quite similar to the example: - Foo is in a vector: std::vector<Foo *> - Bar and other derived classes of Foo are allocated and put in the vector - The content of Foo derived classes consists of (X from 0 to 9): - - a function pointer and X parameters - - or an object pointer, a member function pointer and X parameters - - or an object pointer, a const member function pointer and X parametersIt's a signal and slot system. So someone may attach a member function pointer to the std::vector. However, at one point I allow people to remove member function pointers by their object pointer, or by their object pointer and member function pointer. So if you add member function pointers of an instance of class F, you can delete them all by passing a pointer to the instance of class F to disconnect(). However, now we don't know the type of the parameters of the member function pointer. We never use the parameters themselves though, we only check if the instance the member function pointer is connected to is equal to the object pointer passed to disconnect().   template <class T>unsigned int connect(T *object, void (T::*member_function)());   template <class T, class P> unsigned int connect(T *object, void (T::*member_function)(P *));   template <class T>void disconnect(const T *object); // we never know template parameter P for member function pointers with parameters   template <class T>void disconnect(void (T::*member_function)()); // not sure if this and the next one is actually usefull   template <class T, class P> void disconnect(void (T::*member_function)(P *));   template <class T>void disconnect(const T *object, void (T::*member_function)());   template <class T, class P> void disconnect(const T *object, void (T::*member_function)(P *));EDIT: maybe the visitor pattern would be applicable here?   