Get type of the parameter, templates, C++

前端 未结 2 1714
星月不相逢
星月不相逢 2021-02-20 00:41

There is the following simplified data structure:

Object1.h

template 
class Object1
{
  private:
     T a1;
     T a2;
  public:
     T g         


        
2条回答
  •  甜味超标
    2021-02-20 00:48

    Add a typedef :

    template 
    class Object1
    {
      private:
         T a1;
         T a2;
      public:
         T getA1() {return a1;}
         typedef T type;
    };
    
    template 
    void foo(Object *o1, Object *o2)
    {
       typename Object::type x = o1.getA1();
       ...
    }
    

提交回复
热议问题