Gast
#6394901
Habe in einem bestehenden Projekt eine Funktion, in der am Anfang aus
einem "Object" ein "Window" konstruiert wird:
void GraphicsWnd::auto_created(std::string template_name, Object object)
{
Window mywnd(object);
...
Nun habe ich aber das Problem, dass ich dieses "Window" "später" noch
brauche. Dafür habe ich als ersten Versuch in die Klasse "GraphicsWnd"
eine "globale" Variable eingefügt:
Window wnd;
Und somit sieht die Funktion jetzt so aus, und das funktioniert
natürlich:
void GraphicsWnd::auto_created(std::string template_name, Object object)
{
Window mywnd(object);
wnd = mywnd;
...
Ist aber unschön. Hatte gedacht, es würde nun auch so gehen:
void GraphicsWnd::auto_created(std::string template_name, Object object)
{
wnd(object);
...
Kompiliert aber nicht. Und das hier kompiliert, funktioniert aber
natürlich nicht, da das "globale" "wnd" dann leer bleibt:
void GraphicsWnd::auto_created(std::string template_name, Object object)
{
Window wnd(object);
...
Die Konstruktion ist in der "Window" Klasse so definiert. Glaube
zumindest, dass es die richtige Stelle ist:
// Construct a Window from an Object that refers to a Window
Window(const Object &other) : ShowFullObject(other)
{check_toolbox_class(Window::TOOLBOX_CLASS);}
Kann mir jemand erklären, wie diese Konstruktion überhaupt funktioniert?