C++ Template - Multiple types

前端 未结 3 1033
旧时难觅i
旧时难觅i 2021-01-30 17:08

consider the following class template:

template 
class MyClass
{
   void MyFunc();
};

template 
void MyClass::MyFunc()
{
          


        
3条回答
  •  生来不讨喜
    2021-01-30 17:23

    What you're doing is fine, try this out:

    template 
    struct Structure
    {
      S s ;
      T t ;
    
    } ;
    
    int main(int argc, const char * argv[])
    {
      Structure ss ;
      ss.s = 200 ;
      ss.t = 5.4 ;
    
      return 1;
    }
    

    This code works. If you're getting strange errors, see if you forward declared Structure using only 1 template parameter (that's what I was doing).

提交回复
热议问题