questions on class definitions and mixins

Patrick D. Jeeves pdj9 at pitt.edu
Mon Feb 10 07:34:57 PST 2014


One thing I've been trying to figure out is how to do the 
following in D:

class foo
{
     string bar();
};

void foo::bar()
{
     return "hello world!";
}

 From what I can gather constructs like this just aren't allowed 
in D, but I don't understand why, can anyone explain it please?  
I know they're only in C++ because it uses #include instead of 
importing compiled modules, but I find it hard to quickly get a 
general idea of what a class is supposed to do when there are 
function definitions strewn about it.

The other thing I want to know is about the mixin() command, and 
what the limitations of it are; I know it runs an interpreted 
version of D, but I get the feeling that it isn't as powerful as 
the compiled version, because no one seems to have tried making 
something like this:

class example : File
{
      mixin(d.flex(`lex_file.l`));
      mixin(d.bison(`bison_file.y`));
};

void main()
{
      example("some_file.txt");
      example.yyparse();
};

Is this because it isn't possible to do such things, or because 
it would be rather pointless to do so compared to simpler 
approaches, (in this case calling the C function output by 
flex/bison).




More information about the Digitalmars-d-learn mailing list