this is really creepy: the same(!) instance of the singleton factory sees different addresses of the class static variable, depending on the compilation unit. Please note that the type of the concrete factory function is *erased* when exiting the constructor function of ConfigurableHolder
28 lines
588 B
C++
28 lines
588 B
C++
|
|
#include "clang-static-init.hpp"
|
|
|
|
|
|
test::Subject&
|
|
localFunction()
|
|
{
|
|
return test::fab.get();
|
|
}
|
|
|
|
|
|
int
|
|
main (int, char**)
|
|
{
|
|
cout << "\nStart Testcase: invoking two instances of the configurable singleton factory...\n\n";
|
|
|
|
test::Subject& ref1 = test::fab.get();
|
|
test::Subject& sub2 = test::fabricate(); ///NOTE: invoking get() from within another compilation unit reveales the problem
|
|
test::Subject& sub3 = localFunction();
|
|
|
|
cout << "sub1=" << &ref1
|
|
<< "\nsub2="<< &sub2
|
|
<< "\nsub3="<< &sub3
|
|
<< "\n";
|
|
|
|
|
|
return 0;
|
|
}
|