是否具有返回抽象类型的函数标头合法
Is having a function header that return an abstract type legal?
我想知道根据C++标准以下内容是合法的:
struct Abstract { virtual ~Abstract() = 0; };
auto get_type() -> Abstract;
// I use `get_type` only to extract the return type.
using MyType = decltype(get_type());
GCC 6.3 接受它,但 Clang 3.9 拒绝它。
但是,如果我这样做:
auto get_type() -> struct Abstract;
struct Abstract { virtual ~Abstract() = 0; };
using MyType = decltype(get_type());
现在两个编译器都接受它。在这种情况下,他们都错了吗?
在[class.abstract]中,非常简单:
抽象类不得用作参数类型、函数返回类型或显式转换的类型。
任何尝试执行此类操作的代码都是格式不正确的。
相关文章:
- 为什么在我的函数类型后使用引用运算符 (&) 允许我修改它返回的值?
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 是否有任何建议来统一函数类型限定符并简化可恶的函数类型?
- 关于 C++ 中的函数类型定义
- 用于检测函数类型是否为否的特征
- 函数类型参数的模板参数推导
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- C++无效的函数类型转换
- STL 函数和函数类型与函数指针类型
- 如何将result_of与函数类型定义一起使用
- 将模板(没有规范)传递给 std::thread() 会出现错误:<未解析的重载函数类型>匹配错误
- C++ 编译错误:gnu_printf是无法识别的格式函数类型
- 专门用于"direct"函数类型(与函数指针类型相对)
- 将函数类型作为模板参数传递不会编译
- 通过参数传递 lambda(无函数类型模板)
- 如何在模板参数中分离函数类型返回类型和参数
- 为什么比较函数类型需要指定为模板参数?
- 带有限定符的函数类型定义用例
- 如何声明对函数类型的常量引用
- 非类型模板参数允许各种函数类型?