harttle.github.io icon indicating copy to clipboard operation
harttle.github.io copied to clipboard

2015/09/23/effective-cpp-53

Open utterances-bot opened this issue 7 years ago • 2 comments

Effective C++ 53:注意编译警告 | Harttle Land

请严肃对待所有warning,要追求最高warning级别的warning-free代码;但不要依赖于warning,可能换个编译器有些warning就不在了。

https://harttle.land/2015/09/23/effective-cpp-53.html

utterances-bot avatar Dec 04 '18 01:12 utterances-bot

问个蠢问题,根据作者的代码加了实现

class B {
public:
	virtual void f() const;
	int a;
};
void B::f() const
{
	cout << "B::f()" << endl;
}
class D :public B {
public:
	virtual void f();
	int b;
};
void D::f()
{
	cout << "D::f()" << endl;
}

warning: D::f() hides virtual B::f()

把编译选项设置成了

EnableAllWarnings (/Wall)

还是无效,只输出了,什么都没输出 。
为什么会这样 。
在MSVC和clang++下面都没有报错:

ghost avatar Dec 04 '18 01:12 ghost

看到了

Warning	C4264	'void B::f(void) const': no override available for virtual member function from base 'B'; function is hidden	

ghost avatar Dec 04 '18 01:12 ghost