Hi, I've seen this problem already on other forums, but I still haven't found concrete answer or it's sollution. This is exercise 32, chapter 10, from "Thinking in C++" by Bruce Eckel:
In a header file, create a class Mirror that contains two data members: a pointer to a Mirror object and a bool. Give it two constructors: the default constructor initializes the bool to true and the Mirror pointer to zero. The second constructor takes as an argument a pointer to a Mirror object, which it assigns to the object’s internal pointer; it sets the bool to false. Add a member function test( ): if the object’s pointer is nonzero, it returns the value of test( ) called through the pointer. If the pointer is zero, it returns the bool. Now create five cpp files, each of which includes the Mirror header. The first cpp file defines a global Mirror object using the default constructor. The second file declares the object in the first file as extern, and defines a global Mirror object using the second constructor, with a pointer to the first object. Keep doing this until you reach the last file, which will also contain a global object definition. In that file, main( ) should call the test( ) function and report the result. If the result is true, find out how to change the linking order for your linker and change it until the result is false.
So the question is, how should I change linking order?? And if the linking order would be cahnged is it really possible that this function would return false??
I mean, as for me, no matter in what order this objects would be initialized, cause while initializing they don't need the value of the object, they just need the address. The point is that before main() all of them would be initialized, and the result can't be false, is it?
Thanks in advance:)
But that's not the case, here. The constructor for each object doesn't require any other object to be initialized. The addresses are static, so no undefined behavior could possibly be triggered.