错误:没有上下文类型信息的重载函数的地址

编程入门 行业动态 更新时间:2024-10-21 09:36:05
本文介绍了错误:没有上下文类型信息的重载函数的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

代码:

class que { public: que operator++(int) {} // 1 que &operator++() {} que &operator+=(int n) { que& (que::*go)(); go = 0; if(n > 0) go = &que::operator++ ; // 2 //go = (n > 0) ? (&que::operator++) : 0 ; // 3 } }; int main() { que iter; iter += 3; return 0; }

我想将第2行替换为第3行("if"语句替换为?:"). 如果我取消注释3,则编译器会给我一个错误. 如果我删除第1行,则第3行有效. 问题是:编译器向我要什么? 错误:错误:没有上下文类型信息的重载函数的地址 编译器:gcc-4.5.2

I want to replace line 2 by line 3("if" statement for "?:"). If I uncomment 3, compiler gives me an error. If I delete line 1, then line 3 works. Question is: what does compiler want from me? Error: error: address of overloaded function with no contextual type information Compiler: gcc-4.5.2

推荐答案

错误:没有上下文类型信息的重载函数的地址

error: address of overloaded function with no contextual type information

有两个具有operator++名称的函数(即消息的重载函数"位),您需要指定所需的函数(即上下文类型信息"之一):

There are two functions with the operator++ name (that's the 'overloaded function' bit of the message), you need to specify which one you want (that's the 'contextual type information' one):

n > 0 ? (que& (que::*)())&que::operator++ : 0

您必须考虑到上面的子表达式独立于封闭的完整表达式,即对go的赋值.因此,它必须本身是正确的,即它不能使用go的类型来选择正确的重载,因为它不是此特定子表达式的一部分.

You have to consider that the above subexpression is independent from the enclosing full expression, the assignment to go. So it must be correct on its own, i.e. it can't use the type of go to pick the correct overload because it's not part of this particular subexpression.

更多推荐

错误:没有上下文类型信息的重载函数的地址

本文发布于:2023-11-14 09:30:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586845.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   函数   错误   类型   地址

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!