D
DJ Franke
Hi !
The following code compiles on the Borland5 C++ compiler (simplified
version):
class SomeClass{
public:
SomeClass() {
Son = NULL;
}
SomeClass(const SomeClass& sc) {
Son = sc.Son;
}
SomeClass& find() { return *Son; }
SomeClass* Son;
};
SomeClass Useless = Useless.find();
In the case where I encountered it, the find function did do quite some
things and caused a very understandable runtime error, since Useless
was not intialised at that stage.
I looked at the code in the debugger and the standard constructor is
never called; the find function is called first and then the copy
constructor, which means that Useless is known and can be used before
it is initialised.
I am not very good an the language internals, so my question is wether
this is a bug in the compiler, or wether there is a good reason that
this is allowed to happen.
Thanks
The following code compiles on the Borland5 C++ compiler (simplified
version):
class SomeClass{
public:
SomeClass() {
Son = NULL;
}
SomeClass(const SomeClass& sc) {
Son = sc.Son;
}
SomeClass& find() { return *Son; }
SomeClass* Son;
};
SomeClass Useless = Useless.find();
In the case where I encountered it, the find function did do quite some
things and caused a very understandable runtime error, since Useless
was not intialised at that stage.
I looked at the code in the debugger and the standard constructor is
never called; the find function is called first and then the copy
constructor, which means that Useless is known and can be used before
it is initialised.
I am not very good an the language internals, so my question is wether
this is a bug in the compiler, or wether there is a good reason that
this is allowed to happen.
Thanks