在模板朋友函数内部自我指针

时间:2018-01-12 13:18:15

标签: c++ templates compiler-errors friend-function

如何在友元函数中获取指向对象的指针?

def.h

class A
{
public:
     template <typename some_type_t>
     friend void foo(some_type_t &val);

     A();
     virtual ~A();    
private:
     int x;
     inline A* GetSelfPtr(){return this;}
};

class B
{
public:
      template <typename some_type_t>
      friend void foo(some_type_t &val);

      B();
      virtual ~B();    
private:
      int x;
      inline B* GetSelfPtr(){return this;} 
};
#include "templt.h"

templt.h

template <typename some_type_t>
void foo(some_type_t &val)
{
     GetSelfPtr()->x;
}

错误:'GetReqPtr'没有依赖于模板参数的参数,因此'GetReqPtr'的声明必须可用[-fpermissive]

0 个答案:

没有答案