C++构造函数中调用虚函数导致报错

https://www.geeksforgeeks.org/calling-virtual-methods-in-constructordestructor-in-cpp/

#include 
#include 

using namespace std;


class Father {
public:
	Father () {
		// func(); //compiler will warning
		indirect_call(); //compiler won't warning
	};
	
	void indirect_call() {
		func();
	}
	
	virtual void func() = 0;
};

class Son : Father {
public:	
	void func() override {}
};

int main (void)
{
	Son a;
}

你可能感兴趣的:(c++,c++,开发语言)