Author |
Topic |
|
Frunobulax
Ketchup Master
84 Posts |
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
|
"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
|
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 |
|
|
farrago
New Member
3 Posts |
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? |
|
|
farrago
New Member
3 Posts |
Posted - Feb 28 2008 : 07:38:07 AM
|
Minor correction to the above...I meant VS2005 not 2008... |
|
|
feline
Whole Tomato Software
United Kingdom
19014 Posts |
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. |
zen is the art of being at one with the two'ness |
|
|
support
Whole Tomato Software
5566 Posts |
Posted - Dec 01 2008 : 07:50:49 AM
|
case=12798 is fixed in build 1709 |
|
|
Frunobulax
Ketchup Master
84 Posts |
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
|
"The nice part about being a pessimist is that you are constantly being either proven right or pleasantly surprised." (George F. Will)
|
|
|
sean
Whole Tomato Software
USA
2817 Posts |
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. |
|
|
|
Topic |
|