Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 1626: Chaining of -> operators in C++

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Frunobulax Posted - Feb 12 2008 : 04:38:51 AM
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


7   L A T E S T    R E P L I E S    (Newest First)
sean Posted - Jan 06 2009 : 3:53:31 PM
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.
Frunobulax Posted - Jan 06 2009 : 08:48:28 AM
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
support Posted - Dec 01 2008 : 07:50:49 AM
case=12798 is fixed in build 1709
feline Posted - Feb 28 2008 : 1:40:51 PM
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.
farrago Posted - Feb 28 2008 : 07:38:07 AM
Minor correction to the above...I meant VS2005 not 2008...
farrago Posted - Feb 28 2008 : 07:19:43 AM
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?
feline Posted - Feb 12 2008 : 3:52:27 PM
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.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000