Originally Posted by
laserlight
That will only work if b (and c) will never be bound to another pointer.
I just try writting some codes to reach it:
Code:
#include <iostream>
using namespace std;
class myintpointer{
public:
myintpointer(){
p2 = 0;
p = 0;
}
myintpointer(int* p){
this->p = p;
p2 = this;
}
operator int* (){
if (p2==this)
return p;
else
return *p2;
}
int* operator = (int *p){
this->p = p;
p2 = this;
}
myintpointer* operator = (myintpointer *p){
p2 = p;
}
private:
int *p;
myintpointer *p2;
};
int main(){
myintpointer a = new int;
myintpointer b, c;
*a = 1000;
c = b;
b = a;
cout << *a << " " << *b << endl;
delete a;
c = new int(2000);
b = c;
cout << *c << " " << *b << endl;
return 0;
}
I hope it helps.