using a typedefed variable with library classes

Bill Baxter wbaxter at gmail.com
Sat Jan 10 15:46:40 PST 2009


On Sun, Jan 11, 2009 at 8:23 AM, Charles Hixson
<charleshixsn at earthlink.net> wrote:
> Is it possible to use a typedefed variable with library classes?
>
> In particular, what I've done is:
>
> typedef  int  TestType;
> TestType  t;
> File      f;
>
> t = 42;
> f.write (t);
>
> And the response I get is the compiler asking whether I want to write bytes
> or a long.
>
> Am I doing something grossly wrong?  Or is typedef just broken?  Or is it
> really supposed to work that way for some not-understood reason?
> (alias works fine...but this seems to make typedef basically useless. Unless
> there's a way of adding functions to the library classes [like file] so that
> they'll understand how to cast the typedefed variable.)
>

I've never found a use for typedef myself.  I don't think it's used
much, so it could be that it's a special case that Andrei didn't
consider when re-writing write()  [at least I'm assuming you're
talking D2, based on the error message].  Or it could be that it is a
bug with the compiler.  But either way I think no one uses it, so it's
likely to flush out lots of corner cases.

--bb


More information about the Digitalmars-d-learn mailing list