J
Jason Heyes
Is the expression
p->member
equivalent to this one?
(*p).member
I have a class that overloads both -> and *. Here is part of it.
class SharedPtr
{
Foo *p;
public:
Foo *operator->() { return p; }
Foo &operator*() { return *p; }
};
Is it a waste of effort implementing both operators or do I actually need
both? Say I write
SharedPtr p;
p->bar;
and I remove operator-> from SharedPtr, will that code still compile? Does
the compiler translate it into this?
SharedPtr p;
(*p).bar;
Any help is appreciated.
p->member
equivalent to this one?
(*p).member
I have a class that overloads both -> and *. Here is part of it.
class SharedPtr
{
Foo *p;
public:
Foo *operator->() { return p; }
Foo &operator*() { return *p; }
};
Is it a waste of effort implementing both operators or do I actually need
both? Say I write
SharedPtr p;
p->bar;
and I remove operator-> from SharedPtr, will that code still compile? Does
the compiler translate it into this?
SharedPtr p;
(*p).bar;
Any help is appreciated.