Get type of the parameter, templates, C++

前端 未结 2 1753
星月不相逢
星月不相逢 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 01:09

    You can use this:

    template  class Object, class T>
    void func1(Object &o1, Object &o2)
    {
       T x = o1.getA1();
    }
    

    Working example at http://www.ideone.com/t8KON .

    Btw. if you use pointers as parameters, you have to use -> operator to call methods.

提交回复
热议问题