Caller graph for overloaded operators in Visual Studio 2005

拈花ヽ惹草 提交于 2020-01-16 13:13:34

问题


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

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).

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?

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:


  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.

  2. 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<.

  3. It is extremely hard to find all calls to overloaded operators in code due to templates and the precompiler: C++ IDE for Linux with smart reference searching



来源:https://stackoverflow.com/questions/2516308/caller-graph-for-overloaded-operators-in-visual-studio-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!