C++ frequently questioned answers
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Sat Oct 27 02:02:39 PDT 2007
Bruce Adams wrote:
>
> [OT]
> Someone at work pointed out this java chestnut recently. If you've used java much you will know it but it may come as a shock to a mainly C++ coder.
>
> class foo {
> bar x;
> void foo () {
> x = new bar();
> }
> }
>
> foo is NOT a constructor its actually a method named foo. The java compiler or interpreter generates a default constructor that sets all members to null so any use of x in any method of foo will result in a null pointer exception. This apparently compiles with no warnings.
> [/OT]
What's so surprising about that, even for a Java newcomer?
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list