opAssign and classes
BCS at pathilink.com
Sun Dec 24 22:30:36 PST 2006
Bill Baxter wrote:
> I wrote a class with an opAssign.
> But I find I keep getting bitten by this:
> MyType x = value;
> When I should be typing:
> MyType x = new MyType;
> x = value;
> Somehow I just keep forgetting to do that.
> Then I get a nice nondescript "Error: Access violation" at some unknown
> point in my program that I have to track down.
> Anyone else find themselves making this kind of error?
> Any thoughts for how I or the compiler could help protect against this
> kind of mistake?
1> convert a seg-v to an exception (signal ??)
2> implement poor man's stack tracing:
debug scope(failure) writef(__FILE__":"~itoa!(__LINE__));
> I thought I could stick a check for 'this is null' in the opAssign
> method but that doesn't help because apparently it's dereferencing the
> null pointer to look up opAssign's address that causes the Error, not
> what happens in the call itself.
More information about the Digitalmars-d