You can make the editor’s constructor private, which would prevent others from creating it, and then force the System friend to give it access to the constructor.
class System {
public:
System() : editor_(new Editor()) { ... }
private:
Editor* editor_;
}
class Editor {
friend class System;
Editor() { ... }
}
source
share