A
Anon Email
Hi people,
I'm playing around with Bartosz Milewski's code at the moment, and I
got the following strange results upon execution of the code included
further below. Please be aware that I deliberately tweaked the code to
produce these results:
Matter for 0 created
Hello from world 1.
Matter for 2009196833 created
Hello from world 2.
Good bye from world 2.
Matter in 2009196833 annihilated
Good bye from world 1.
Matter in 0 annihilated
The code is:
#include <iostream>
class Matter
{
public:
Matter (int i)
: _identifier (i)
{
std::cout << " Matter for " << _identifier << " created\n";
}
~Matter ()
{
std::cout << " Matter in " << _identifier << " annihilated\n";
}
private:
const int _identifier;
};
class World
{
public:
World (int i)
: _identifier (i), _matter (_identifier) // initializing
embeddings
{
std::cout << "Hello from world " << _identifier << ".\n";
}
~World ()
{
std::cout << "Good bye from world " << _identifier << ".\n";
}
private:
const Matter _matter; // Embedded object of type Matter
const int _identifier;
};
World TheUnivers (1);
int main ()
{
World myWorld (2);
}
Now, I know that "int" should be declared before "Matter" in class
"World". I deliberately changed the order to check out the results.
What on earth is 2009196833? Shouldn't this value be zero, as there is
no preceding initialization for the "Matter" object within the
"myWorld" object? i.e., the "Matter" for both "World" objects should
be equal to zero...?
Strange.
Deets
I'm playing around with Bartosz Milewski's code at the moment, and I
got the following strange results upon execution of the code included
further below. Please be aware that I deliberately tweaked the code to
produce these results:
Matter for 0 created
Hello from world 1.
Matter for 2009196833 created
Hello from world 2.
Good bye from world 2.
Matter in 2009196833 annihilated
Good bye from world 1.
Matter in 0 annihilated
The code is:
#include <iostream>
class Matter
{
public:
Matter (int i)
: _identifier (i)
{
std::cout << " Matter for " << _identifier << " created\n";
}
~Matter ()
{
std::cout << " Matter in " << _identifier << " annihilated\n";
}
private:
const int _identifier;
};
class World
{
public:
World (int i)
: _identifier (i), _matter (_identifier) // initializing
embeddings
{
std::cout << "Hello from world " << _identifier << ".\n";
}
~World ()
{
std::cout << "Good bye from world " << _identifier << ".\n";
}
private:
const Matter _matter; // Embedded object of type Matter
const int _identifier;
};
World TheUnivers (1);
int main ()
{
World myWorld (2);
}
Now, I know that "int" should be declared before "Matter" in class
"World". I deliberately changed the order to check out the results.
What on earth is 2009196833? Shouldn't this value be zero, as there is
no preceding initialization for the "Matter" object within the
"myWorld" object? i.e., the "Matter" for both "World" objects should
be equal to zero...?
Strange.
Deets