Is the following safe? I know, strictly speaking, dereferencing a pointer before the thing to which it points has been properly constructed seems dangerous, but I imagine the compiler will just provide a pointer without actually doing any dereferencing. Well, I assume.
(Note: gInst doesn t actually use the reference until much later.)
TU 1
Sys::System::System::System(const sf::VideoMode& rVM, const std::string& rSTR, unsigned long settings) :
win(rVM, rSTR, settings),
gInst(*this)
{
}
Header A
namespace Sys
{
namespace System
{
struct System;
}
namespace UI
{
struct GUI
{
System::System& topl;
MenuBar menu;
GUI(System::System&);
private:
GUI();
GUI(const GUI&);
GUI& operator=(const GUI&);
};
}
}
标题B
namespace Sys
{
namespace System
{
struct System
{
sf::RenderWindow win;
Sys::UI::GUI gInst;
Sys::Editor::Editor eInst;
System(const sf::VideoMode&, const std::string&, unsigned long);
private:
System();
System(const System&);
System& operator=(const System&);
};
void start();
}
}