Code fails with linker error. Why?
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Oct 6 05:36:31 PDT 2014
On Mon, 06 Oct 2014 11:54:55 +0000
John Colvin via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> I disagree. It's simple and easy to understand.
and hackish.
> This is the only genuine problem I can see that requires a
> language extension. Separating class definition from method
> definition in to different compilation units doesn't allow access
> to private members without very nasty hacks.
no hacks needed.
== pkg.classdef.d ==
module pkg.classdef;
class A {
private:
int hiddenField;
int bar ();
}
== pkg.othermodule.d ===
module pkg.othermodule;
import pkg.classdef;
// this imlements A.bar() declared in pkg.classdef:
@implementation(A) int bar () { return this.hiddenField; }
compiler is perfectly able to put A.bar() implementation in the scope
of A, and then A.bar can access anything in A. it's the same as
declaring bar() in class definition.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141006/af91837a/attachment.sig>
More information about the Digitalmars-d-learn
mailing list