Visual Studio 2005中重载运算符的调用器图 [英] Caller graph for overloaded operators in Visual Studio 2005

查看:283
本文介绍了Visual Studio 2005中重载运算符的调用器图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为重载的运算符获得调用者图?

Is is possible to get a callers graph for overloaded operators?

我有一个简单的结构,它具有自然排序,我通过重载关系运算符来表示。回过头来看看,我在定义 operator> 时犯了一个错误。我已经设置大于简单地返回运算符< 的否定(这不正确,因为这将意味着(val1> val2) == val1 == val2

I have a simple struct with a natural ordering which I have represented by overloading the relational operators. Looking back through the code, it appears that I made a mistake in defining operator >. I had set the greater than to simply return the negation of operator < (this is not correct as this will mean that (val1 > val2) == true when val1 == val2).

我想检查在其余代码中调用> 运算符的位置,以确保没有意想不到的后果。这似乎不可能使用Visual Studio 2005调用浏览器。当我搜索函数时,它识别在代码中定义它的位置,但是列表中没有对该函数的调用,但是不是这样。

Anyway before fixing this, I want to check where the > operator is called in the rest of the code to make sure there are no unintended consequences. This does not seem to be possible using the Visual Studio 2005 call browser. When I search for the function, it recognises where it is defined in the code, but lists there being no calls to or from that function, which is not the case.

除了在我的项目代码中搜索>的所有实例,我还有其他选项吗?

Aside from searching through all instances of ">" in my project code do I have any other options?

此页 - http://msdn.microsoft.com/en-us/magazine/cc163658.aspx#S3 - 表示检测操作符调用不是最初在VS2005中的,但我不能确定这是否改变了。

This page - http://msdn.microsoft.com/en-us/magazine/cc163658.aspx#S3 - indicates that detecing operator calls is not something that was originally in VS2005, but I can't tell if this has changed.

推荐答案


  1. 除非val1和val2实例的类具有自己实现 operator> 的基类,建议您删除 operator> 从头和cpp文件中重新编译。这应该给你一个由编译器保证的对 operator> 的所有调用的列表。

  1. Unless the class of which val1 and val2 are instances of has base classes that themselves implement operator> I suggest you remove your definition of operator> from the header and cpp files and recompile. This should give you a list of all calls to operator> guaranteed by the compiler.

Boost.Operators 可以帮助避免将来出现此类错误。如果您提供运算符== ,则可以自动提供 operator!= > operator operator> operator> = $ c> operator

Boost.Operators may help to avoid such errors in the future. It can automatically provide operator!= if you provide operator== e.g., the same goes for operator<=, operator> and operator>= if you provide operator<.

由于模板和预编译器,在代码中找到所有对重载运算符的调用: http://stackoverflow.com/questions/2514350/2514529#2514529

It is extremely hard to find all calls to overloaded operators in code due to templates and the precompiler: http://stackoverflow.com/questions/2514350/2514529#2514529

这篇关于Visual Studio 2005中重载运算符的调用器图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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