On 6/11/07, Christopher Smith <[EMAIL PROTECTED]> wrote:
template <typename T>
class Ptr {
public:
    Ptr(T* a) : ptr(a) {}
    Ptr(Ptr<T>& a) : ptr(a.ptr) {}
    T& operator*() const { return *operator->(); }
    T* operator->() const { if (nullptr == a) { throw
null_pointer_exception(); } return a; }
    bool operator==(const Ptr<T>& a) const { return ptr == a.ptr; }
    Ptr<T>& operator=(const Ptr<T>& a) { ptr = a.ptr; }

private:
    T* ptr;
};

Now you can avoid that error in C++ (not to mention abusing pointer
arithmetic). You're welcome.

WHY???? Why would I prefer that over Java, C# or Python where these
semantics are built in and I'll never forget to type "Ptr(...)"?

And what does this do to compilation speed? Runtime bloat? Cognitive
load on the programmer?

-Chuck

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to