成员函数调用decltype [英] Member function call in decltype
本文介绍了成员函数调用decltype的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码:
struct A
{
int f(int);
auto g(int x) -> decltype(f(x));
};
无法编译时出现错误:
error: cannot call member function 'int B::f(int)' without object
如果我将其更改为:
struct A
{
int f(int);
auto g(int x) -> decltype(this->f(x));
};
我得到另一个错误:
error: invalid use of 'this' at top level
错了这两个?我使用的是gcc 4.6
What is wrong with either of these? I am using gcc 4.6
推荐答案
目前您只能访问this >函数体,但这很可能会很快改变:
Currently you can only access 'this' and members of the class inside the function body, but this is likely to be changed soon:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1207
这篇关于成员函数调用decltype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文