В файле A.h у меня есть:
Код: Выделить всё
class A
{
private:
int a;
class AnonClass;
friend class AnonClass;
};
Код: Выделить всё
namespace
{
class AnonClass
{
public:
AnonClass(A* parent)
{
parent->a = 0; // This doesn't work, a is not accessible
}
};
}
В Java вы можете объявить анонимные классы, так что это будет очень похоже. Также он не будет предоставлять AnonClass клиентам A.h
Подробнее здесь: https://stackoverflow.com/questions/198 ... space-in-c
Мобильная версия