读书人

有没有静态友元函数也乃是static fr

发布时间: 2013-06-26 14:29:32 作者: rapoo

有没有静态友元函数,也就是static friend f();这样的函数
大家来看,某大师写了这样一个友元函数,我惊讶地发现居然有个static,友元函数可以是静态的吗?


class A
{
public:
A(){x=0;}
static friend void hanshu();
private:
int x;
};
void hanshu()
{
A a;
cout<<a.x;
}

[解决办法]
引用:
Quote: 引用:

11.4 Friends
3 A function first declared in a friend declaration has external linkage (3.5). Otherwise, the function retains
its previous linkage (7.1.1).

6 No storage-class-specifier shall appear in the decl-specifier-seq of a friend declaration.

什么意思?


你不是要看标准的说法吗? 给你贴出来又看不懂...
简单地说,这种写法是错的. friend 的声明不能有 static 或 extern

读书人网 >C++

热点推荐