gpt4 book ai didi

c++ - obj.template operator() 构造不适用于 xlC 11.1

转载 作者:太空狗 更新时间:2023-10-29 21:28:08 25 4
gpt4 key购买 nike

下面一段C++代码:

template <typename T>
static void execute(T& obj) {
obj.template operator()<int>();
}

当使用 IBM 的 xlC 11.1 编译时会产生错误消息:1540-0063 (S) The text "operator"is unexpected。如果我使用函数而不是运算符,它可以正常工作,但我不想重写很多库代码。有没有其他方法可以使 .template operator 构造与 xlC 一起工作?

最佳答案

获得 .template operator 的最佳方式工作的构造是向 IBM 提交错误报告。

此代码符合 C++ 标准。事实上,这是编写此代码的唯一合法方式。


提交报告时,您可以使用以下内容作为证据:

§14.2/4状态:

When the name of a member template specialization appears after . or -> in a postfix-expression ... and the object expression of the postfix-expression is type-dependent ... the member template name must be prefixed by the keyword template. ...


第一部分:“the name of a member template specialization ”,适用是因为 operator()<int>是成员模板特化的名称。 §14.2/1 中有这方面的证据:

A template specialization can be referred to by a template-id:

§14.2/1然后为匹配 operator()<int>template-id 指定语法.


第二部分:“and the object expression of the _postfix-expression_ is
type-dependent
”,适用于 obj是类型依赖的。 obj由于 §14.6.2.2/3 而依赖于类型:

An id-expression is type-dependent if it contains: - an identifier associated by name lookup with one or more declarations declared with a dependent type, ...

在这种情况下,objT& 有关,这是一个依赖类型(因为 T 是一个模板参数)。


这只是确定性答案的一半,因为我没有为我提出的许多主张提供引用。不过,我已经做了一个小时了,所以可能是时候停下来了。

关于c++ - obj.template operator() 构造不适用于 xlC 11.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7674695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com