lundi 11 février 2019

Can I use templates here?

I have the following piece of code:

int CreatePropertiesDialog(int type, void *object)
{
    if( type == 1 )
    {
        ClassA *a = static_cast<ClassA *>( object );
        // build the properties dialog
    }
    if( type == 2 )
    {
        ClassB *b = static_cast<ClassB *>( object );
        // build the properties dialog
    }
    // display the properties dialog
}

However, the use of void* type sounds very ugly.

Can this code be improved by using template? Or maybe some other means?

Aucun commentaire:

Enregistrer un commentaire