On Tue, 14 Apr 2009 17:01:28 -0400, Andrew Spott <andrew.sp...@gmail.com> wrote:

So, the attached is supposed to be a class that creates a vector of any type (I would like it to only take numerical values (int, float, real, double, etc), however, I am ok with it taking others (not that I see why someone would use it that way).

I tried to compile it with the following, but it won't compile. I don't really understand the errors I'm getting either.

Can someone tell me what I'm doing wrong? If you need more information, let me know.

-Andrew

void testvector() {
        auto v = new Vector!(float)(3, 12.0);
        writefln(v.toString());
        int n = 0;
        
        while (n < n.size()) {
                v[n] = n;
        }
        
        writefln(v.toString());

}

Try the attached (untested).

You might get some insight into how d should be written by looking at the changes.

BTW, if this is just an exercise fine, but your example is a completely redundant implementation of standard builtin arrays.

e.g., the following code does almost the same thing you are doing without requiring a new class:

void testvector() {
        auto v = new float[3];
        v[0..$] = 12.0;
        writefln(v);
        int n = 0;

        while(n < v.length) { // bug in original code
                v[n] = n;
                n++; // bug in original code
        }       
        
        writefln(v);
}


-Steve

Attachment: vector.d
Description: Binary data

Reply via email to