torkell: (Default)
[personal profile] torkell
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().
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

May 2025

S M T W T F S
    123
45678910
111213141516 17
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 18th, 2025 05:00 am
Powered by Dreamwidth Studios