Thomas (boggyb) wrote,
Thomas
boggyb

  • Mood:

Another C++ surprise

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().
Tags: computing
Subscribe

  • Quote of the day

    From a meeting the other day about the carol service St John's is putting together... A: "...and I'll see if I can find someone with a better voice…

  • Trigger's broom laptop

    pleaseremove and I, discussing moving Windows activations to new hardware... pleaseremove: ...it'll work up to when a tech…

  • Random quote

    Random comment from an American friend at virtual pasta night last Monday, chatting about the clusterfuck that is Dominic Cummings-gate: "Y'know how…

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments