I want to overload array opperator (->) as a standard operator for pointers and additionaly whant to show somethink on the console.
And I did ...
Gamer.h file (Gamer class with nested Collecion class) :
class Gamer {
class Collection
{
public:
Collection();
Collection* operator->();
}
public:
Gamer();
Collection *deck;
}
Gamer.cpp
...
Gamer::Collection* Gamer::Collection::operator->()
{
cout << "Pointer on deck >> " << this << endl;
return this;
}
...
main.cpp - here i declare and alloc memory for Gamer object who have collection field inside (as pointer)
Gamer *gamer;
Gamer::allocGamer(gamer);
When i want to use overloaded array opperand I can't do :
gamer->deck->();
But I can :
gamer->deck->operator->();
The question is why I cant just call gamer->deck->(); and have to call gamer->deck->operator->(); instead ?
And second question - How I should overload arrow opperand to have direct access to overloaded opperand like gamer->deck->(); ?