?

Log in

No account? Create an account
Another C++ surprise - 'Twas brillig, and the slithy toves did gyre and gimble in the wabe [entries|archive|friends|userinfo]
Thomas

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

Links
[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

Another C++ surprise [Saturday 6th May 2017 at 3:55 pm]
Thomas

boggyb
[Tags|]
[Feeling |surprisedsurprised]

Did you know that the following code will compile?

#include <stdio.h>

class Foo {
public:
  Foo();
  ~Foo();

  void FrobSomething(void* something);
};

Foo::Foo() {
  printf("New foo!\n");
}

Foo::~Foo() {
  printf("Destroyed foo!\n");
}

void main() {
  Foo foo;
}


No, the surprise isn't the slightly incorrect definition of main(). The surprise is that the Foo class is declared as containing a FrobSomething() method, but there's no implementation of the method. C++ is perfectly happy with this as long as you never actually try to call FrobSomething().
Link | Previous Entry | Share | Next Entry[ Penny for your thoughts? ]