newbie: Access violation because of "class"
Ellery Newcomer
ellery-newcomer at utulsa.edu
Thu Apr 29 19:01:22 PDT 2010
On 04/29/2010 08:50 PM, Larry Luther wrote:
> Why do I get an "object.Error: Access Violation" in the following code?
> If I change "class" to "struct" and remove "public:" I don't get an error.
> I'm using D2.
>
> import std.stdio;
>
> class Plane {
> public:
> int
> xres,
> yres;
> };
>
>
> void main (string[] args) {
> Plane
> p;
> p.xres = 1920;
> }
>
>
>
>
>
because 'Plane p;' is short for 'Plane p = null;'
I bet you want 'Plane p = new Plane();'
or if you want it allocated on the stack, I think
'scope Plane p = new Plane();'
should work.
More information about the Digitalmars-d-learn
mailing list