According to C++ Primer 5th Edition,
"It is worth noting that we can provide a definition for a pure virtual. However, the function body must be defined outside the class. That is, we cannot provide a function body inside the class for a function that is = 0."
However, the code below works for me in VS2015. Could anyone explain why?
struct A
{
virtual void fn1() = 0 { cout << "A::fn1()" << endl; }
};
struct B : public A
{
virtual void fn1() override { cout << "B::fn1()" << endl; }
};
int main()
{
B b;
b.fn1(); // "B::fn1()"
b.A::fn1(); // "A::fn1()"
cin.get(); return 0;
}