Code fails with linker error. Why?
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Oct 4 04:19:44 PDT 2014
On Sat, 04 Oct 2014 11:01:28 +0000
John Colvin via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> On Saturday, 4 October 2014 at 10:38:32 UTC, ketmar via
> Digitalmars-d-learn wrote:
> > On Sat, 04 Oct 2014 10:27:16 +0000
> > John Colvin via Digitalmars-d-learn
> > <digitalmars-d-learn at puremagic.com>
> > wrote:
> >
> >> Sorry, but that's just not how it works. There is no
> >> requirement for the definition of a function to be found in
> >> the same compilation unit as it's declaration.
> > is there any possibility to declare *class* *method* in one
> > file and to
> > implement it in another? O_O
> >
> > i doubt so.
>
> Yes, you can. You just have to get the mangling right.
and how about access to class fields? manual mangling is a half-working
hack. alas. i really want to have some normal and non-hackish way to
separate class definition and class implementation. besides, your trick
is faulty, 'cause it misses hidden 'this' parameter. try that:
// methodLink.d
class A { void foo(int n); }
void main () { auto a = new A; a.foo(42); }
// missingMethod.d
import methodLink;
import std.stdio;
pragma(mangle, A.foo.mangleof)
void foo(int n) { writeln("n=", n); }
it writes gibberish and segfaults.
-------------- 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/20141004/002b706e/attachment.sig>
More information about the Digitalmars-d-learn
mailing list