digitalmars.D.learn - Need help with simple event framework
- Tano Sakaria (145/145) Nov 19 2011 Hello guys,
- Kagamin (1/1) Nov 19 2011 You escape pointer to stack allocated object.
- Tano Sakaria (2/2) Nov 19 2011 Why can't I do that?
- Jacob Carlborg (4/6) Nov 19 2011 Allocate the object on the heap using "new".
- Tano Sakaria (4/4) Nov 19 2011 I'm sorry, but I don't understand.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (17/21) Nov 19 2011 Without seeing the original code, foo() below returns a pointer to an
- Tano Sakaria (8/8) Nov 20 2011 When I do that, I get an error "Cannot implicitly convert type
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (50/60) Nov 20 2011 That error must have been changed since D1. I get a similar one when I
- Tano Sakaria (1/1) Nov 20 2011 Thanks a lot, it works now!
Hello guys, I need some help regarding a (very) basic Event handling framework I just started on today. Please note that I'm still fairly new to programming itself and that I might not know things that seem obvious to others. The attached file is my work so far. I have a class called Backbone which houses 2 pointers for a linked list. Every linked list member contains 2 private pointers (one forward and one backward), the associated public functions to acces them, a string for the Event_ID and a function pointer to the function that shall be called, if an event with the corresponding Event_ID is invoked. I also have a simple test class with exactly one function to test whether the function is indeed called. I can compile without problems, but I get a runtime error "Access Violation: Read at address 0x4E4". This runtime error gets thrown once I call the function getNext() through a pointer, but I honestly have no idea why. I am using D1 and Tango, though Tango is only for the line printing and can easily be converted to Phobos. I hope you can help me! begin 644 Backbone.d M__YI`&T`<`!O`'(`=`` `'0`80!N`&<`;P`N`&D`;P`N`%,`=`!D`&\`=0!T M`#L M`"``/0` `&X`90!W`"``0 !A`&,`:P!B`&\`; !E`" `*0`[``T`" `)`%0` M90!S`'0`0P!L`&$`<P!S`"``9`!E`'(`(``]`"``; !E`'<`(`!4`&4`<P!T M`$,`;`!A`',`<P`[``T`" `)`'0`:`!E`$(`80!C`&L`8 !O`&X`90`N`'(` M90!G`&D`<P!T`&4`< !%`'8`90!N`'0`2`!A`&X`9`!L`&4`< `H`"``( !T M`&4`<P!T`%\`10!6`$4`3 !4`"(`+`` `"8`9`!E`'(`+ !T`&4`<P!T`"`` M*0`[``T`" `)`&(`;P!O`&P`(`!B`&P`80` `#T`(`!F`&$`;`!S`&4`.P`- M``H`"0!B`'D`=`!E`%L`8P!H`&$`< !;`%T`70!;`%T`(`!D`&4`< !P`#L` M`&X`=``H`"``( !T`&4`<P!T`%\`10!6`$4`3 !4`"(`+`` `"(`= !O`&D` M9`!?`&T`80!I`&X`( `L`"``9`!E`'(`<`` `"D`.P`-``H`"0!]``T`" `) M``T`" `)`&,`;`!A`',`<P` `%0`90!S`'0`0P!L`&$`<P!S``T`" `)`'L` M`" `(`!%`'8`90!N`'0`(`!E`'8`90!N`'0`*0` `'L`(`!3`'0`9`!O`'4` M8P!L`&$`<P!S`"``0 !A`&,`:P!B`&\`; !E`"``>P`-``H`"0`-``H`<`!R M`&D`= !A`'0`90`Z``T`" `)`$ `80!N`&0`;`!E`'(`3`!I`&X`:P`J`"`` M9 !I`'(`<P!T`$P`:0!N`&L`.P`-``H`"0!(`&$`; !D`&P`90!R`$P`:0!N M`&L`* ` `&P`80!S`'0`3`!I`&X`:P`[``T`" `)`$ `80!N`&0`;`!E`'(` M3`!I`&X`:P`J`"``8P!U`'(`< !E`&X`=`!,`&D`; !K`#L M`'``=0!B`&P`:0!C`#H M`'<`(`!(`&$`; !D`&P`90!R`$P`:0!N`&L`*`` `"(`( `L`"``; !U`&P` M;``L`"``; !U`&P`;``L`"``; !U`&P`;`` `"D`.P`-``H`"0`)`&8`:0!R M`',`=`!,`&D`; !K`"``/0` `"8`:`!L`#L M/0` `&X`90!W`"``2`!A`&X`9`!L`&4`< !,`&D`; !K`" `(``B`"(`+`` M`&X`=0!L`&P`+`` `&X`=0!L`&P`+`` `&X`=0!L`&P`(``I`#L M"0`O`"\`;`!A`',`=`!,`&D`; !K`"``/0` `"8`:`!L`#L M``H`"0`-``H`"0!B`&\`;P!L`"``< !E`&<`:0!S`'0`90!R`$4`= !E`&X` M=`!(`&$`; !D`&P`90!R`" `(`!C`& `80!R`%L`70` `&4`= !E`&X`=`!? M`&D`9``L`"``:0!N`'0`(`!D`&4`;`!E`&<`80!T`&4`*`!%`'8`90!N`'0` M*0` `&8`<`` `"D`(`![``T`" `)`&,`=0!R`'(`90!N`'0`3`!I`&X`:P` M`#T`(`!F`&D`< !S`'0`3`!I`&X`:P`N`&<`90!T`$X`90!X`'0`*``I`#L` M90!R`$P`:0!N`&L`(`!H`&P`(``]`"``; !E`'<`(`!(`&$`; !D`&P`90!R M`$P`:0!N`&L`*`` `&4`= !E`&X`=`!?`&D`9``L`"``9 !P`"P`(`!N`'4` M;`!L`"P`(`!N`'4`;`!L`"``*0`[``T`" `)``D`"0!H`&P`+ !S`&4`=`!. M`&4`>`!T`" `(``F`& `;`` `"D`.P`-``H`"0`)``D`9 !I`'(`<P!T`$P` M:0!N`&L`(``]`"``) !H`&P`.P`-``H`"0`)``D`;`!A`',`=`!,`&D`; !K M`"``/0` `&8`:0!R`',`=`!,`&D`; !K`#L M?0` `&4`;`!S`&4`(`![``T`" `)``D`"0!(`&$`; !D`&P`90!R`$P`:0!N M`&L`(`!H`&P`(``]`"``; !E`'<`(`!(`&$`; !D`&P`90!R`$P`:0!N`&L` M*`` `&4`= !E`&X`=`!?`&D`9``L`"``9 !P`"P`(`!L`&$`<P!T`$P`:0!N M`&L`+`` `&X`=0!L`&P`(``I`#L M:P`N`',`90!T`$X`90!X`'0`*`` `"8`:`!L`"``*0`[``T`" `)``D`"0!L M:`!A`'(`6P!=`"``90!V`&4`; !T`%\`:0!D`"P`(`!C`& `80!R`%L`70` M`',`;P!U`'(`8P!E`"P`(`!B`'D`=`!E`%L`8P!H`&$`< !;`%T`70!;`%T` M`"``90!V`'0`(``]`"``; !E`'<`(`!%`'8`90!N`'0`*`` `&4`= !E`&X` M=`!?`&D`9``L`"``<P!O`'4`< !C`&4`+`` `&0`80!T`&$`(``I`#L M``D`"0!C`'4`< !R`&4`; !T`$P`:0!N`&L`(``]`"``9 !I`'(`<P!T`$P` M:0!N`&L`.P`-``H`"0`)``T`" `)``D`=P!H`&D`;`!E`" `(`!C`'4`< !R M`&4`; !T`$P`:0!N`&L`+ !G`&4`=`!.`&4`>`!T`" `*0` `"$`:0!S`"`` M`$P`:0!N`&L`+ !P`'(`;P!C`&4`<P!S`$4`= !E`&X`=``H`"``90!V`'0` M(``I`#L M`'4`< !R`&4`; !T`$P`:0!N`&L`+ !G`&4`=`!.`&4`>`!T`" `*0`[``T` M`'0`< !U`&4`.P`-``H`"0!]``T`" `)``T`" `)``T`" `)``T`" !]``T` M" `-``H`8P!L`&$`<P!S`"``2`!A`&X`9`!L`&4`< !,`&D`; !K`"``>P`- M``H`<`!R`&D`= !A`'0`90`Z``T`" `)`$ `80!N`&0`;`!E`'(`3`!I`&X` M:P`J`"``; !E`' `=`!(`&$`; !D`&P`90!R`$P`:0!N`&L`.P`-``H`"0!( M`&$`; !D`&P`90!R`$P`:0!N`&L`* ` `'``< !E`'8`:0!O`'4`<P!(`&$` M; !D`&P`90!R`$P`:0!N`&L`.P`-``H`"0`-``H`"0!C`& `80!R`%L`70` M`&4`= !E`&X`=`!?`&D`9``[``T`" `)``T`" `)`&D`; !T`"``9`!E`&P` M90!G`&$`=`!E`" `10!V`&4`; !T`"D`(`!F`'4`; !C`'0`:0!O`&X`5`!O M`$,`80!L`&P`.P`-``H`"0`-``H`<`!U`&(`;`!I`&,`. `-``H`"0`-``H` M"0!T`& `:0!S`" `8P!H`&$`< !;`%T`(`!E`'8`90!N`'0`7P!I`&0`+`` M`&D`; !T`"``9`!E`&P`90!G`&$`=`!E`" `10!V`&4`; !T`"D`(`!D`&<` M+`` `$ `80!N`&0`;`!E`'(`3`!I`&X`:P`J`"``<`!R`&4`= !I`&\`=0!S M`"P`(`!(`&$`; !D`&P`90!R`$P`:0!N`&L`* ` `&X`90!X`'0`*0` `'L` M`"``90!V`&4`; !T`%\`:0!D`#L M5`!O`$,`80!L`&P`(``]`"``9`!G`#L M`'8`:0!O`'4`<P!(`&$`; !D`&P`90!R`$P`:0!N`&L`(``]`"``<`!R`&4` M= !I`&\`=0!S`#L M`&X`:P` `#T`(`!N`&4`>`!T`#L M" `)`$ `80!N`&0`;`!E`'(`3`!I`&X`:P`J`"``9P!E`'0`4`!R`&4`= !I M`&\`=0!S`" `*0`-``H`"0![``T`" `)``D`< !E`'0`=0!R`&X`(`!P`'(` M90!V`&D`;P!U`',`2`!A`&X`9`!L`&4`< !,`&D`; !K`#L M``H`"0`-``H`"0!(`&$`; !D`&P`90!R`$P`:0!N`&L`* ` `&<`90!T`$X` M`'0`2`!A`&X`9`!L`&4`< !,`&D`; !K`#L M"0!B`&\`;P!L`"``<P!E`'0`3 !E`' `=``H`"``2`!A`&X`9`!L`&4`< !, M`&D`; !K`"H`(`!N`&4`>`!T`"``*0`-``H`"0![``T`" `)``D`; !E`' ` M=`!(`&$`; !D`&P`90!R`$P`:0!N`&L`(``]`"``; !E`' `=``[``T`" `) M``D`< !E`'0`=0!R`&X`(`!T`'(`=0!E`#L M"0!B`&\`;P!L`"``<P!E`'0`4`!R`&4`= !I`&\`=0!S`" `(`!(`&$`; !D M>P`-``H`"0`)`'``< !E`'8`:0!O`'4`<P!(`&$`; !D`&P`90!R`$P`:0!N M`&L`(``]`"``<`!R`&4`= !I`&\`=0!S`#L M; ` `'0`< !U`&4`.P`-``H`"0!]``T`" `)``T`" `)`&(`;P!O`&P`(`!P M`'(`;P!C`&4`<P!S`$4`= !E`&X`=``H`"``10!V`&4`; !T`"``90!V`&4` M; !T`"``*0`-``H`"0![``T`" `)``D`:0!F`" `(`!T`& `:0!S`"X`90!V M`&4`; !T`%\`:0!D`"``/0`]`"``90!V`&4`; !T`"X`9P!E`'0`20!$`" ` M`$,`80!L`&P`*`` `&4`= !E`&X`=`` `"D`.P`-``H`"0`)``D`< !E`'0` M=0!R`&X`(`!T`'(`=0!E`#L M`&X`(`!F`&$`;`!S`&4`.P`-``H`"0!]``T`" `)``T`" !]``T`" `-``H` M8P!L`&$`<P!S`"``10!V`&4`; !T``T`" ![``T`" !P`'(`:0!V`&$`=`!E M`#H M"0!C`& `80!R`%L`70` `',`;P!U`'(`8P!E`#L M`&,`:`!A`'(`6P!=`%T`6P!=`"``90!V`&4`; !T`$0`80!T`&$`.P`-``H` M"0`-``H`<`!U`&(`;`!I`&,`. `-``H`"0!T`& `:0!S`" `8P!H`&$`< !; M`%T`(`!E`'8`90!N`'0`7P!I`&0`+`` `&,`:`!A`'(`6P!=`"``<P!O`'4` M< !C`&4`+`` `&(`>0!T`&4`6P!C`& `80!R`%L`70!=`%L`70` `&4`= !E M90!N`'0`7P!I`&0`(``]`"``90!V`&4`; !T`%\`:0!D`#L M`& `:0!S`"X`<P!O`'4`< !C`&4`(``]`"``<P!O`'4`< !C`&4`.P`-``H` M"0`)`'0`:`!I`',`+ !E`'8`90!N`'0`1`!A`'0`80` `#T`(`!E`'8`90!N M`'(`90!T`'4`< !N`"``<P!O`'4`< !C`&4`.P`-``H`"0!]``T`" !]```` ` end
Nov 19 2011
Why can't I do that? What can I do to circumvent this?
Nov 19 2011
On 2011-11-19 21:51, Tano Sakaria wrote:Why can't I do that? What can I do to circumvent this?Allocate the object on the heap using "new". -- /Jacob Carlborg
Nov 19 2011
I'm sorry, but I don't understand. How can I use "new" in conjunction with a pointer? "new" creates an object, but don't I need a pointer to said object instead for my linked list?
Nov 19 2011
On 11/19/2011 01:22 PM, Tano Sakaria wrote:I'm sorry, but I don't understand. How can I use "new" in conjunction with a pointer? "new" creates an object, but don't I need a pointer to said object instead for my linked list?Without seeing the original code, foo() below returns a pointer to an object allocated on the heap: struct S {} S * foo() { S * p = new S; return p; } void main() { S * p = foo(); } That object belongs to the D runtime and may be destroyed at an unspecified time when there are no more references to it. Ali
Nov 19 2011
When I do that, I get an error "Cannot implicitly convert type HandlerLink to HandlerLink*". By the way, how can I split up my classes into seperate source files? Just copying the code into one file per class and changing the imports doesn't work. I tried compiling the classes seperately, into libraries and what not, but all I get is Linker-errors as soon as compiling the Backbone class. Setting the -I flag for the import path does not work, either.
Nov 20 2011
I could not figure out how to see Backbone.d, so I cannot see your code. On 11/20/2011 01:52 AM, Tano Sakaria wrote:When I do that, I get an error "Cannot implicitly convert type HandlerLink to HandlerLink*".That error must have been changed since D1. I get a similar one when I return a pointer to a 'class' variable as opposed to a 'struct' variable. If you are really using a class, then you don't need a pointer: class S {} S foo() { /* * The left hand side is a class variable, while the * anonymous object that has been created with new on the * right hand side is a clas object. Class objects are * accessed by class variables. * * They are different things. They are confusing because * the object is defined as 'class S{}' earlier and * its reference variable is defined as 'S var'. (I think * * Returning the class variable from the function is fine * because the actual object lives in the heap. */ S var = new S; return var; } void main() { S var = foo(); } Please provide a smaller code in plain text. (Some people put their code on a clipboard-like code site. You can do that too if the code is too long.)By the way, how can I split up my classes into seperate source files?(Note: It would be better if this question had its separate thread.) The following is on Linux. I think the object file extensions are .obj on Windows.Just copying the code into one file per class and changing the imports doesn't work.You must give those files to the compiler as well. Assuming the program has the main module (deneme.d) and two others: $ dmd deneme.d hayvan/kedi.d hayvan/kopek.dI tried compiling the classes seperately,That works too. Assuming that the two modules have been compiled with the -c flag to generate their .o files: $ dmd deneme.d hayvan/kedi.o hayvan/kopek.ointo librariesThat works too. First make a library that consists of the modules: $ dmd hayvan/kedi.d hayvan/kopek.d -lib -ofhayvan Then use that library when building the program: $ dmd deneme.d hayvan.a Most of the above are from one of the not-yet-translated chapters of D.ershane: http://ddili.org/ders/d/moduller.htmland what not, but all I get is Linker-errors as soon as compiling the Backbone class. Setting the -I flag for the import path does not work, either.-I is for the location of the import files; it doesn't involve compilation. Ali
Nov 20 2011