如何在友元函数中获取指向对象的指针?
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]