digitalmars.D.learn - newbie: Access violation because of "class"
- Larry Luther (15/15) Apr 29 2010 Why do I get an "object.Error: Access Violation" in the following code?
- Ellery Newcomer (6/21) Apr 29 2010 because 'Plane p;' is short for 'Plane p = null;'
- bearophile (4/7) Apr 30 2010 D classes are not like C++ classes, they are managed by reference only, ...
- Larry Luther (1/1) Apr 30 2010 Thanks for your help.
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;
}
Apr 29 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.
Apr 29 2010
Larry Luther: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.D classes are not like C++ classes, they are managed by reference only, as in Java. See the scope keyword too. Bye, bearophile
Apr 30 2010









Ellery Newcomer <ellery-newcomer utulsa.edu> 