1
考慮下面的代碼:構造結構與私人會員
class A
{
private:
struct B { private: int i; friend class A; };
public:
static void foo1()
{
B b;
b.i = 0;
}
static void foo2()
{
B b = {0};
}
};
爲什麼foo1工作,但不foo2的? A類不是結構體初始化構造函數嗎?無論如何要在C++ 11中完成這項工作嗎?
(注意,刪除私人品牌foo2的工作。)