Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 10, 2007 alias & typedef | ||||
---|---|---|---|---|
| ||||
Hi, I just wan't to know the differences between 'alias' and 'typedef' as both do the same thing. Thanks |
January 10, 2007 Re: alias & typedef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heinz | Heinz wrote: > Hi, > > I just wan't to know the differences between 'alias' and 'typedef' as both do > the same thing. > > Thanks Aliases provide another name for an existing type. Typedefs declare a new type which happens to be identical to an existing type. This can matter in function overloading, for instance: alias int IntAlias; typedef int IntTypedef; void foo(int i) { } // #1 void foo(IntAlias i) { } // #2 ERROR: Ambiguous with #1 void foo(IntTypedef i) { } // #3 Okay void main() { int i = 1; IntAlias j = 2; IntTypedef k = 3; foo(i); // ERROR: Call #1 or #2? foo(j); // ERROR: Call #1 or #2? foo(k); // Okay, call #3 } -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org |
January 10, 2007 Re: alias & typedef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heinz | Heinz wrote: > Hi, > > I just wan't to know the differences between 'alias' and 'typedef' as both do > the same thing. I think the spec is pretty clear: http://www.digitalmars.com/d/declaration.html#typedef Have you read that yet? --bb |
January 10, 2007 Re: alias & typedef | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> Heinz wrote:
>> Hi,
>>
>> I just wan't to know the differences between 'alias' and 'typedef' as both do
>> the same thing.
>
> I think the spec is pretty clear:
> http://www.digitalmars.com/d/declaration.html#typedef
>
> Have you read that yet?
And read the next few sections too.
For example, nobody has yet mentioned that alias is useful for more than just types.
|
Copyright © 1999-2021 by the D Language Foundation