can I use SFINAE to selectively define a member variable in a template class?

后端 未结 4 1693
不知归路
不知归路 2020-12-28 18:43

So what I want to do is to create a template class which may or may not contain a member variable based on the template argument passed in. like following:

t         


        
4条回答
  •  再見小時候
    2020-12-28 19:30

    I think this is what you are looking for.

    The class template does not have any member data by default.

    template
    class base
    {
    };
    

    Add a specialization of the class template that has the member data.

    template
    class base
    {
       foov m_var;
    };
    

提交回复
热议问题