Dynamic array of objects
gummybears via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 27 15:00:15 PDT 2016
Hi,
Today thought lets learn D. I am writing a compiler for a language
and read D compiles very fast.
Switched my compiler from C++ to D and ran my test suite to use D.
Doing somethin wrong as creating array of objects gives me a
segmentation fault
Example
import std.stdio;
class Pair {
float x;
float y;
this() { x = 0; y = 0; }
}
void main() {
Pair[] arr;
// segmentation fault on next line
arr = new Pair[](10);
arr[0].x = 3;
arr[0].y = 4;
writef("arr[0] = (%f,%f)",arr[0].x,arr[0].y);
}
More information about the Digitalmars-d-learn
mailing list