[Solved] How to choose among two classes given a condition in c++? [closed]

[ad_1]

Assuming you need to create object at compile time depending on a variable, you can try something like following

class class1{};
class class2{};

int main( int argc, char *argv[] )
{
    constexpr bool variable =true;

    /* x is object of type class1 or class2 depending on 
       compile time constant 'variable'
    */

    typedef std::conditional<variable, class1, class2>::type x;


    //std::cout << typeid(x).name() << '\n';
    return 0;
}

See Here

1

[ad_2]

solved How to choose among two classes given a condition in c++? [closed]