I do not understand the behavior of this fragment: (compiled with clang ++ 3.0)
#include <iostream> using namespace std; class Base { public: virtual void bar() {} bool foo = false; }; class Derived : public Base{ public: Derived() { Base::foo = true; } }; int main() { Derived d; Base b(d); cout << b.foo << endl; // prints 0 // prints 1 if "virtual void bar() {}" is removed }
Why does the function Base :: bar () have any effect on copying Base :: foo?
source share