Implementing a non template method defined in a template class

前端 未结 5 872
盖世英雄少女心
盖世英雄少女心 2021-01-04 08:14

When I want to define a method declared in a template class, but that the method doesn\'t depend on the template parameters, have I to define it in the include files as :

5条回答
  •  独厮守ぢ
    2021-01-04 08:48

    You need to do it this way:

    template class
    void MyClass::myMethod()
    {
       ...
    }
    

    It's not the method that is templated, it's the class.

    You can have a templated method in a non-templated class, a non-templated method in a templated class (your case) and a templated method in a templated class, and of course a non-templated method in a non-templated class.

提交回复
热议问题