Thanks for the advice!
@2) I already discovered that on my own... almost caused me some nasty bugs.
@3) Good idea, will do! Feels a bit weird however that compilers allow it.
@4) Cannot judge whether I should do this. The benefit you mentioned is obvious, however it has a couple of minuses:
- It could be important to know whether you are using a such a "smart pointer", or a regular one (for example if you are optimizing for speed). Calling .GetElement() every time will quietly remind you and forcefully save you from carbon-based memory failures.
- If another programmer reads your code, he will quietly be informed that you are using a "smart pointer".
Of course, I could implement the overloading. Then I could use my judgement which notation is more suitable... but then again, I've been programming long enough to know not to trust my judgement :)
Although I've never really had a situation where such a class would be useful, it's an interesting idea. |
My situation is I am writing a calculator parser. Originally, each node in the expression tree was a rational number. Then I started adding more and more data structures (Polynomials, weyl algebra elements, Universal enveloping algebra elements, .... (the sizes of those rise exponentially with the size of their names ;) ).
Originally I was allocating an empty object of every type in each node. (Those include hash tables, etc.). Then I figured out allocating 1000 nodes was 500MB RAM... you get the idea...