为什么我不能用`= delete;`声明一个纯虚函数? [英] Why can't I declare a pure virtual function with `= delete;`?

查看:575
本文介绍了为什么我不能用`= delete;`声明一个纯虚函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

纯虚拟函数使用通用语法进行修改:

Pure virtual functions are delcared with the common syntax :

virtual f() = 0; 

然而,由于c ++ 11有一种方式来传递显式的 (特殊)成员函数的存在

Yet, since c++11 there's a way to communicate the explicit non existence of a (special) member function :

Mystruct() = delete; // eg default constructor



Q



为什么不能将此语法扩展到纯虚函数以便实现通信这种操作的一致性? :

Q

Why isn't this syntax extended to pure virtual functions in order to achieve uniformity in communicating such operations ? :

virtual f() = delete; 



注意



,因为标准说这样!。我想知道这背后的原因(ing),以及是否有一个建议(或意图)这样的东西。

Note

I know the obvious answer is because the Standard says so!. I'm wondering about the reason(ing) behind this and whether there ever was a proposal (or an intention) for something like this.

推荐答案

= delete; 虚拟。与删除的函数不同,纯虚函数不会使一个程序选择它作为重载解析的结果。

= delete; means something entirely different from making a function pure virtual. Unlike deleted functions, a pure virtual function does not make ill-formed a program that selects it as the result of overload resolution.

这篇关于为什么我不能用`= delete;`声明一个纯虚函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆