Templates
BCS
BCS at pathlink.com
Tue Jan 15 10:27:19 PST 2008
Lorenzo Villani wrote:
> Hi, i have a little problem with a simple class (please note that I'm a D newbie)
>
> The folllowing is an initial implementation of a Vector class using templates, modeled after Qt's QVector. As you might notice this is a class wrapper around dynamic sized arrays.
>
> (there's only a little part of the code implemented)
>
> module std.Vector;
>
> class Vector(T) {
[...]
> }
>
> Now, if I build a very simple test program such as
>
> import std.stdio;
> import std.Vector;
>
> int main() {
> Vector!(Object) myVec;
> myvec.size();
> return 0;
> }
>
classic D error, try this:
Vector!(Object) myVec = new Vector!(Object)();
All objects are by reference and are, by default set to null, NOT newed.
If you want a stack allocated type use structs.
>
> The application would compile fine but give a segfault when running. I'm running Linux with Digital Mars D Compiler v1.015 on a Fedora 8 box.
>
> PS: Can you tell me why the compiler doesn't let me use consts in functions declarations?
const in 1.x is true const, compile time known values like #define does
in C.
More information about the Digitalmars-d
mailing list