我们是否可以增加这种面向密钥的访问保护模式的可重用性:
class SomeKey {
friend class Foo;
// more friends... ?
SomeKey() {}
// possibly non-copyable too
};
class Bar {
public:
void protectedMethod(SomeKey); // only friends of SomeKey have access
};
Run Code Online (Sandbox Code Playgroud)
为了避免持续的误解,这种模式不同于律师 - 客户的习惯用语:
(在这个问题中提出了一个侧面讨论,因此我打开了这个问题.)
在C++ 03中,以下是非法的,尽管有些编译器支持它.
template <class T>
class X
{
friend T;
};
Run Code Online (Sandbox Code Playgroud)
这是否已在C++ 11中合法化?(抱歉,我没有时间自己阅读草稿,只是希望有人知道这一点)
嘿,如果你能告诉我编译器对我的方法做了什么,我很感激.如果我跟它一起打电话给Area(10.1,10.1);我102.那么.01减产?你有一个很好的网站,我可以获得有关这个特定主题的信息吗?thx你的时间!
float Area (float length, float width){
int result;
result = length*width;
return result;
}
Run Code Online (Sandbox Code Playgroud)