Need help with simple event framework

Ali Çehreli acehreli at yahoo.com
Sun Nov 20 08:09:27 PST 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
      * this is the same in Java and perhaps C#.)
      *
      * 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.d

 > I 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.o

 > into libraries

That 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.html

 > 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.

-I is for the location of the import files; it doesn't involve compilation.

Ali



More information about the Digitalmars-d-learn mailing list