D - Templates, interfaces, access violation problem
- =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= (38/38) Mar 21 2004 Having a little problem here with the code below. It compiles all right,...
- =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= (6/6) Mar 21 2004 Fllrb! Obviously, I am still living the the C++ dreamscape where an
- J Anderson (15/19) Mar 21 2004 Yes and no.
- Matthew (5/22) Mar 21 2004 This should be done. The auto qualifier prevents it from being ambiguous...
- =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= (18/45) Mar 21 2004 Mmhm. Remember what the thread was named (just out of curiousity)? I'm
- Matthew (8/51) Mar 21 2004 It's appropriate to have to write new when you're constructing a heap ba...
- Phill (5/45) Mar 22 2004 Does this mean that you are the first DWoman
- =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= (6/58) Mar 22 2004 No, it means I like writing 'she' where everyone else (it seems) likes
- Phill (4/62) Mar 22 2004 fair enough :o))
Having a little problem here with the code below. It compiles all right, but when run it gives me the descriptive error message of "Error: Access Violation". What am I doing wrong? template StreamInterfaces(T) { interface ReadableStreamInterface { void read(out T[] buffer, in uint number); void sync(); } } template MemoryStream(T) { class MemoryStream : StreamInterfaces!(T).ReadableStreamInterface { void read(out T[] buffer, in uint number) { printf("read\n"); } void sync() { printf("sync\n"); } } } int main() { alias MemoryStream!(ubyte) MemoryUByteStream; MemoryUByteStream testStream; testStream.sync(); ubyte[] buffer; testStream.read(buffer, 100); return 0; } Cheers, Sigbjørn Lund Olsen
Mar 21 2004
Fllrb! Obviously, I am still living the the C++ dreamscape where an object is automatically constructed when declared. Adding "= new MemoryUByteStream" fixed it. Is there any reason why one has to explicitly 'new' an object? Cheers, Sigbjørn Lund Olsen
Mar 21 2004
Sigbjørn Lund Olsen wrote:Fllrb! Obviously, I am still living the the C++ dreamscape where an object is automatically constructed when declared. Adding "= new MemoryUByteStream" fixed it. Is there any reason why one has to explicitly 'new' an object?Yes and no. Objects in D are pointers to objects not objects themselves, therefore its pretty close to C++ (because u have to use new there as well, except D is one symbol shorter). Whenever u use new, think gc. I think it may be easier to parse as well. Of course the syntax could have been simplified (and this has been discussed before). If you really want the C++ behaviour then it would be the auto version of object creation that you'd want to simplify. auto object o = new object; to auto object o; That was discussed before. -- -Anderson: http://badmama.com.au/~anderson/
Mar 21 2004
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:c3jpf3$rus$1 digitaldaemon.com...Sigbjørn Lund Olsen wrote:This should be done. The auto qualifier prevents it from being ambiguous (to compiler or human) and it removes the quite confusing new'ing of an object that's automatic.Fllrb! Obviously, I am still living the the C++ dreamscape where an object is automatically constructed when declared. Adding "= new MemoryUByteStream" fixed it. Is there any reason why one has to explicitly 'new' an object?Yes and no. Objects in D are pointers to objects not objects themselves, therefore its pretty close to C++ (because u have to use new there as well, except D is one symbol shorter). Whenever u use new, think gc. I think it may be easier to parse as well. Of course the syntax could have been simplified (and this has been discussed before). If you really want the C++ behaviour then it would be the auto version of object creation that you'd want to simplify. auto object o = new object; to auto object o;
Mar 21 2004
J Anderson wrote:Sigbjørn Lund Olsen wrote:Mmhm. Remember what the thread was named (just out of curiousity)? I'm not too fussed about wanting C++ behaviour just for the sake of it - there are too many who'd like D to me an amalgamation of languages Foo, explicitly writing 'new object' isn't going to be a problem, for me at least, as long as I remember to do it. My principal worry is that I'm going to make hordes of bugs while my mind adjusts (and afterwards too?). Error messages, really. I had no idea what was going on for quite a while there, or where it was. Presumably it wouldn't be hard for the compiler to see that 'oh, here's a fool trying to do something to an object that hasn't been constructed - let's throw a compilation error at her' instead of leaving it untill runtime, with as giving a message as "Access Violation, and I'm not going to give you fools a line number, module name, function name, nothing to help you along. So long, and see you next time." (paraphrase) Cheers, Sigbjørn Lund OlsenFllrb! Obviously, I am still living the the C++ dreamscape where an object is automatically constructed when declared. Adding "= new MemoryUByteStream" fixed it. Is there any reason why one has to explicitly 'new' an object?Yes and no. Objects in D are pointers to objects not objects themselves, therefore its pretty close to C++ (because u have to use new there as well, except D is one symbol shorter). Whenever u use new, think gc. I think it may be easier to parse as well. Of course the syntax could have been simplified (and this has been discussed before). If you really want the C++ behaviour then it would be the auto version of object creation that you'd want to simplify. auto object o = new object; to auto object o; That was discussed before.
Mar 21 2004
"Sigbjørn Lund Olsen" <sigbjorn lundolsen.net> wrote in message news:c3jqj9$ti2$1 digitaldaemon.com...J Anderson wrote:It's appropriate to have to write new when you're constructing a heap based object, but it's a dose of cognitive dissonance to have to do it when the object is auto. We don't have to new structs, do we?Sigbjørn Lund Olsen wrote:Mmhm. Remember what the thread was named (just out of curiousity)? I'm not too fussed about wanting C++ behaviour just for the sake of it - there are too many who'd like D to me an amalgamation of languages Foo, explicitly writing 'new object' isn't going to be a problem, for me at least, as long as I remember to do it.Fllrb! Obviously, I am still living the the C++ dreamscape where an object is automatically constructed when declared. Adding "= new MemoryUByteStream" fixed it. Is there any reason why one has to explicitly 'new' an object?Yes and no. Objects in D are pointers to objects not objects themselves, therefore its pretty close to C++ (because u have to use new there as well, except D is one symbol shorter). Whenever u use new, think gc. I think it may be easier to parse as well. Of course the syntax could have been simplified (and this has been discussed before). If you really want the C++ behaviour then it would be the auto version of object creation that you'd want to simplify. auto object o = new object; to auto object o; That was discussed before.My principal worry is that I'm going to make hordes of bugs while my mind adjusts (and afterwards too?). Error messages, really. I had no idea what was going on for quite a while there, or where it was. Presumably it wouldn't be hard for the compiler to see that 'oh, here's a fool trying to do something to an object that hasn't been constructed - let's throw a compilation error at her' instead of leaving it untill runtime, with as giving a message as "Access Violation, and I'm not going to give you fools a line number, module name, function name, nothing to help you along. So long, and see you next time." (paraphrase)The assertion messages are Sh, and need addressing asap. I think there's not much debate on that point, and hopefully Walter'll deal with that just as soon as he's done the whole list of new libraries I just sent him. ;-)
Mar 21 2004
"Sigbjørn Lund Olsen" <sigbjorn lundolsen.net> wrote in message news:c3jqj9$ti2$1 digitaldaemon.com...J Anderson wrote:Does this mean that you are the first DWoman on the NG? Phill.Sigbjørn Lund Olsen wrote:Mmhm. Remember what the thread was named (just out of curiousity)? I'm not too fussed about wanting C++ behaviour just for the sake of it - there are too many who'd like D to me an amalgamation of languages Foo, explicitly writing 'new object' isn't going to be a problem, for me at least, as long as I remember to do it. My principal worry is that I'm going to make hordes of bugs while my mind adjusts (and afterwards too?). Error messages, really. I had no idea what was going on for quite a while there, or where it was. Presumably it wouldn't be hard for the compiler to see that 'oh, here's a fool trying to do something to an object that hasn't been constructed - let's throw a compilation error at her'Fllrb! Obviously, I am still living the the C++ dreamscape where an object is automatically constructed when declared. Adding "= new MemoryUByteStream" fixed it. Is there any reason why one has to explicitly 'new' an object?Yes and no. Objects in D are pointers to objects not objects themselves, therefore its pretty close to C++ (because u have to use new there as well, except D is one symbol shorter). Whenever u use new, think gc. I think it may be easier to parse as well. Of course the syntax could have been simplified (and this has been discussed before). If you really want the C++ behaviour then it would be the auto version of object creation that you'd want to simplify. auto object o = new object; to auto object o; That was discussed before.
Mar 22 2004
Phill wrote:"Sigbjørn Lund Olsen" <sigbjorn lundolsen.net> wrote in message news:c3jqj9$ti2$1 digitaldaemon.com...No, it means I like writing 'she' where everyone else (it seems) likes writing 'him', because it catches people off guard and tends to make them think a little bit. Which can't possibly be a bad thing :-) Cheers, Sigbjørn Lund OlsenJ Anderson wrote:Does this mean that you are the first DWoman on the NG?Sigbjørn Lund Olsen wrote:Mmhm. Remember what the thread was named (just out of curiousity)? I'm not too fussed about wanting C++ behaviour just for the sake of it - there are too many who'd like D to me an amalgamation of languages Foo, explicitly writing 'new object' isn't going to be a problem, for me at least, as long as I remember to do it. My principal worry is that I'm going to make hordes of bugs while my mind adjusts (and afterwards too?). Error messages, really. I had no idea what was going on for quite a while there, or where it was. Presumably it wouldn't be hard for the compiler to see that 'oh, here's a fool trying to do something to an object that hasn't been constructed - let's throw a compilation error at her'Fllrb! Obviously, I am still living the the C++ dreamscape where an object is automatically constructed when declared. Adding "= new MemoryUByteStream" fixed it. Is there any reason why one has to explicitly 'new' an object?Yes and no. Objects in D are pointers to objects not objects themselves, therefore its pretty close to C++ (because u have to use new there as well, except D is one symbol shorter). Whenever u use new, think gc. I think it may be easier to parse as well. Of course the syntax could have been simplified (and this has been discussed before). If you really want the C++ behaviour then it would be the auto version of object creation that you'd want to simplify. auto object o = new object; to auto object o; That was discussed before.
Mar 22 2004
fair enough :o)) "Sigbjørn Lund Olsen" <sigbjorn lundolsen.net> wrote in message news:c3m9ct$1rn5$1 digitaldaemon.com...Phill wrote:except"Sigbjørn Lund Olsen" <sigbjorn lundolsen.net> wrote in message news:c3jqj9$ti2$1 digitaldaemon.com...J Anderson wrote:Sigbjørn Lund Olsen wrote:Fllrb! Obviously, I am still living the the C++ dreamscape where an object is automatically constructed when declared. Adding "= new MemoryUByteStream" fixed it. Is there any reason why one has to explicitly 'new' an object?Yes and no. Objects in D are pointers to objects not objects themselves, therefore its pretty close to C++ (because u have to use new there as well,No, it means I like writing 'she' where everyone else (it seems) likes writing 'him', because it catches people off guard and tends to make them think a little bit. Which can't possibly be a bad thing :-) Cheers, Sigbjørn Lund OlsenDoes this mean that you are the first DWoman on the NG?D is one symbol shorter). Whenever u use new, think gc. I think it may be easier to parse as well. Of course the syntax could have been simplified (and this has been discussed before). If you really want the C++ behaviour then it would be the auto version of object creation that you'd want to simplify. auto object o = new object; to auto object o; That was discussed before.Mmhm. Remember what the thread was named (just out of curiousity)? I'm not too fussed about wanting C++ behaviour just for the sake of it - there are too many who'd like D to me an amalgamation of languages Foo, explicitly writing 'new object' isn't going to be a problem, for me at least, as long as I remember to do it. My principal worry is that I'm going to make hordes of bugs while my mind adjusts (and afterwards too?). Error messages, really. I had no idea what was going on for quite a while there, or where it was. Presumably it wouldn't be hard for the compiler to see that 'oh, here's a fool trying to do something to an object that hasn't been constructed - let's throw a compilation error at her'
Mar 22 2004