Modify const reference data
Adam D. Ruppe
destructionator at gmail.com
Sun Dec 8 19:24:10 PST 2013
Easy problem in class B: data is null!
On Monday, 9 December 2013 at 02:53:01 UTC, Heinz wrote:
> class B
> {
> private const ubyte* data;
> private ubyte[] abc;
>
> this()
> {
> data = cast(const ubyte*)abc.ptr;
> }
Since abc isn't initialized in this constructor, abc.ptr is null.
So data is null too.
> public void print()
> {
> for(size_t i = 0; i < 4; i++)
> {
> writefln("%d", data[i]);
> }
> }
> }
And since data is null, data[i] will be a memory
err/segfault/access violation/whatever it is called.
More information about the Digitalmars-d-learn
mailing list