Is it possible to overload the operator new() to have a different return value than void*?
I have two structures:
One structure (A) just holds data and what not.
The second structure (B) is built to act like a pointer to the first:
struct A;
struct B
{
private:
A* ptr;
public:
A& operator*() { return (*ptr); };
A& operator->() { return (*ptr); };
};
struct A
{
int data;
B operator&() { B ret; ret.ptr = this; return ret; };
};
The idea is as simple as this. I don't want any external classes handling pointers to A, not directly.
However, I do want them to be able to create instances of A. Is there a way to override A's new operator to return an instance of B? Nevermind right now the safety concerns, and handling delete, this is just a simple, reduced example to explain my problem.