Double deref operator

Hello,

I want to override the indircet and dereference operator:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Content {

public:
	void myMethod() {

	}

};

class Container {

private:
	Content content;

public:
	Content* operator->() {
		return &content;
	}

	Content& operator*() {
		return content;
	}

};

int main(int* argc, char** argv) {
	Container* c = new Container;
	// what compiles:
        (*c)->myMethod();
       
        // what I want:
        // c->myMethod();

	return 0;
}


This is jsut a simple example and my usecase has nothing to do with containers. I have a pointer of Container and not an object.

Is this possible and if yes how?
Thanks!
Last edited on
Container c;
I have a pointer of Container and not an object.
you shouldn't have a pointer but an object.
Topic archived. No new replies allowed.