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
  • 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