Hallo, On Wed, 26 Mar 2003, Holger Macht wrote:
Ich möchte ganz einfach auf Daten einer Klasse von einer anderen aus zugreifen.
Auf die Gefahr hin, dass ich mich blamiere: Was spricht eigentlich gegen eine globale Variable (oder eine Instanz einer Klasse)? ==== bar.hh ==== class bar { public: bar(); }; ==== ==== foo.hh ==== class foo { public: foo(); }; ==== ==== main.hh ==== #include <string> #include <iostream> extern string dateiname; ==== ==== bar.cc ==== #include "main.hh" #include "bar.hh" bar::bar() { std::cout << "bar(): " << dateiname << std::endl; }; ==== ==== foo.cc ==== #include "main.hh" #include "foo.hh" foo::foo() { std::cout << "foo(): " << dateiname << std::endl; }; ==== ==== main.cc ==== #include "main.hh" #include "foo.hh" #include "bar.hh" string dateiname; int main(int argc, char * argv[]) { dateiname = "blubb"; std::cout << "main(): " << dateiname << std::endl; foo f; bar b; return 0; } ==== Die Variable kann man ggfs. ja in einen passenden Namespace verpacken. Wenn's mehrere sind, ist wohl eine struct oder eine Klasse verwenden. Man denke z.B. an Kommandozeilenoptionen die "globale flags" setzen (z.B. "verbose", "debug" o.ae.)... -dnh -- "Given the choice of condoms, your gentialia turning green and dropping off, or celerycy^W clebrat^W not getting any, condoms are often a clear winner." -- Chris Hacking in the scary devil monastery