Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 1626: Chaining of -> operators in C++
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Frunobulax
Ketchup Master

84 Posts

Posted - Feb 12 2008 :  04:38:51 AM  Show Profile  Reply with Quote
Hi,

[VS2005 english SP1, C++]
I finally set up a test case of a problem that is bugging me since I started using VAX. Consider the following code:


#include <boost/shared_ptr.hpp>

template <class T>
class MyIterator {
public:
    MyIterator(T value) : _value(value) {}

    T operator*() const { return _value; }
    T operator ->() const { return _value; }
private:
    T _value;
};

struct MyStruct {
    long x,y;
};

typedef boost::shared_ptr<MyStruct> MyPointer;

void main(void)
{
    MyIterator<MyPointer> iter(MyPointer(new MyStruct()));
    long value = iter->x;
}


Now the kick is that C++ chains -> operator until it gets a type that has no -> operator. Thus, the iter->x code is legal and does compile, even though two -> operators are evaluated (first from the iterator and then from boost::shared_ptr).

VAX however only evaluates the first and suggests the boost::shared_ptr members instead of the MyStruct members (I will send a screenshot). This is really annoying because we use lots of shared pointers and a good deal of custom iterators...

Regards, tv



"The nice part about being a pessimist
is that you are constantly being either
proven right or pleasantly surprised."
(George F. Will)

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Feb 12 2008 :  3:52:27 PM  Show Profile  Reply with Quote
I am seeing the same effect here. Thank you for the clear description.

case=12798

I was not aware you could do that in C++, but as you say, it compiles quite happily.

zen is the art of being at one with the two'ness
Go to Top of Page

farrago
New Member

3 Posts

Posted - Feb 28 2008 :  07:19:43 AM  Show Profile  Reply with Quote
Does this only work if you have an explicit operator->()? I just tried it with:

class MyClass
{
  void DoSomething();
}

typedef boost::shared_ptr< MyClass > MyClassPtr;
typedef std::vector< MyClassPtr > MyClassVec;

void main()
{
  MyClassVec aVector;
  MyClassVec::iterator it = aVector.begin();
  it->DoSomething();
}

and VS2008 fails to compile with:
quote:
error C2039: 'DoSomething' is not a member of 'boost::shared_ptr<T>'


The only way it works is if I do:

(*it)->DoSomething();


The only difference between yours and mine seems to be that I am using the standard library iterator and you are using a custom one. So why wouldn't it follow the double dereference that it does in your case?
Go to Top of Page

farrago
New Member

3 Posts

Posted - Feb 28 2008 :  07:38:07 AM  Show Profile  Reply with Quote
Minor correction to the above...I meant VS2005 not 2008...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19014 Posts

Posted - Feb 28 2008 :  1:40:51 PM  Show Profile  Reply with Quote
In my test code I have an explicit operator->() function, and it compiles in both VS2005 and VC6.

Of course, as reported here, VA is confused by the code.

zen is the art of being at one with the two'ness
Go to Top of Page

support
Whole Tomato Software

5566 Posts

Posted - Dec 01 2008 :  07:50:49 AM  Show Profile  Reply with Quote
case=12798 is fixed in build 1709
Go to Top of Page

Frunobulax
Ketchup Master

84 Posts

Posted - Jan 06 2009 :  08:48:28 AM  Show Profile  Reply with Quote
Hi,

quote:
Originally posted by support

case=12798 is fixed in build 1709



it seems the latest versions brought several improvements for us - thanks! However, this particular feature does not always work as it should: VAX does not suggest the member function "insert" (or any other set function) in the example below.


#include <boost/optional.hpp>

void test(void) {
    boost::optional<std::set<long> > maybeSet = std::set<long>();

    maybeSet->insert(0);
};


Regards, tv

"The nice part about being a pessimist
is that you are constantly being either
proven right or pleasantly surprised."
(George F. Will)
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Jan 06 2009 :  3:53:31 PM  Show Profile  Reply with Quote
This is a problem specifically with our parsing of boost::optional (case=2154). I'm sorry I don't have an estimate for when it will be addressed.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000