Issue with operator-> overloaded in VS2010

被刻印的时光 ゝ 提交于 2019-12-24 09:41:44

问题


I've implemented a small framework in C++ which I use in a course I give at college, to help students implement their homework. One of the most valuable classes of that framework, is a smart pointer class, which as you can imagine, it overloads the -> operator.

Recently I upgraded from VS2008 to VS2010, and occasionally I get issues with the intellisense after typing the operator. Instead of showing the methods and fields available in the pointed data type, it shows the methods and fields of the smart pointer class. Note this doesn't happen all the time, but once it happens, it's a little frustrating because I end up wasting a lot of time.

Have you experienced any trouble like this? Any idea or suggestion to work around this will be very appreciated.

This may sound like a minor issue, but It invalidates the use of VS2010 in the course till I can work this out.

Thanks in advanced!

EDIT

I've managed to reproduce the issue in a smaller context. Suppose I have something like this:

template <class T>
struct ptr
{
  T* operator->(){ return 0; }
  void otherMember() {}
};

template <class T>
struct node
{
  T value;
};

template <class T>
void foo()
{
  ptr<node<int>> pi;
  ptr<node<T>> pt;
  pi->value = 10; // OK, intellisense shows 'value'
  pt-> // wrong! intellisense shows 'operator->()' and 'otherMember()', instead of 'value'
}

Does anyone experience the same behavior?

来源:https://stackoverflow.com/questions/4102317/issue-with-operator-overloaded-in-vs2010

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