Skip to content

Instantly share code, notes, and snippets.

@tetsuok
Last active January 21, 2016 10:37
Show Gist options
  • Save tetsuok/563bde9f35e9dd9d5576 to your computer and use it in GitHub Desktop.
Save tetsuok/563bde9f35e9dd9d5576 to your computer and use it in GitHub Desktop.
#include <stdio.h>
class A {
public:
virtual ~A() {}
virtual void f(int) {}
};
class B : public A {
public:
void f(size_t) override {} // error
};
int main() {
A* b = new B;
b->f(0);
return 0;
}
@tetsuok
Copy link
Author

tetsuok commented Jan 21, 2016

// clang++ -std=c++11 -Woverloaded-virtual a.cc
#include <stdio.h>
class A {
 public:
  virtual ~A() {}
  virtual void f(int) { printf("A::f()\n"); }
};

class B : public A {
 public:
  void f(size_t) { printf("B::f()\n"); } // warning
};

int main() {
  B b;
  b.f(0); // B::f()

  A* a = &b;
  a->f(0); // A::f()

  return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment