純粋仮想関数

インスタンス化はできない、と。

#include <iostream>

using namespace std;

class Foo {
public:
  void func() {
    cout << "Foo::func()" << endl;
  }
  virtual void vfunc() = 0;
};

class Bar : public Foo {
public:
  void func() {
    cout << "Bar::func()" << endl;
  }
  void vfunc() {
    cout << "Bar::vfunc()" << endl;
  }
};

int main() {
  Foo foo;
  return 0;
}


$ g++ -g foo.cpp -o foo && ./foo
foo.cpp: In function `int main()':
foo.cpp:24: error: cannot declare variable `foo' to be of type `Foo'
foo.cpp:24: error: because the following virtual functions are abstract:
foo.cpp:10: error: virtual void Foo::vfunc()