can we do alias in namespace?
-
I meet such a situation that there is hundreds of classes in a big namespace, and i just want to borrow something from it. i write something like this: ===================================== namespace big { class apple; class banana; ... } ===================================== namespace small { class apple: big.apple { } } ===================================== But i hope not to use inherit. is there any way to declare a alias or mapping?
-
I meet such a situation that there is hundreds of classes in a big namespace, and i just want to borrow something from it. i write something like this: ===================================== namespace big { class apple; class banana; ... } ===================================== namespace small { class apple: big.apple { } } ===================================== But i hope not to use inherit. is there any way to declare a alias or mapping?
If you mean, give a new name to an existing object; then yes you can do that.
using apple = big.apple;
This only works on a file by file basis though. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971 -
If you mean, give a new name to an existing object; then yes you can do that.
using apple = big.apple;
This only works on a file by file basis though. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971Thank you. But what i exactly want is something like the cpp's #define. #define small.apple big.apple And pick the defines in a single header file, then it will only expose small part of a big library to user. BTW, when i transfer my former cpp code to C#, i find it difficult to do with the #define macro. for example #define AT_LEAST(A,B) ... here A B can be int, float, or double (surely template is another choice). But in C#, #define can only define a symbol served for selected compile. any suggestion?
-
Thank you. But what i exactly want is something like the cpp's #define. #define small.apple big.apple And pick the defines in a single header file, then it will only expose small part of a big library to user. BTW, when i transfer my former cpp code to C#, i find it difficult to do with the #define macro. for example #define AT_LEAST(A,B) ... here A B can be int, float, or double (surely template is another choice). But in C#, #define can only define a symbol served for selected compile. any suggestion?
nova chen wrote: And pick the defines in a single header file, then it will only expose small part of a big library to user. Nope, for that you'll have to create empty wrappers as you had mentioned in the first post. nova chen wrote: But in C#, #define can only define a symbol served for selected compile. This is because #define's aren't type safe, and .NET is extremely type-safe; which is why they took out the ability to use macros in code. In most cases whenever you used a macro you should use a function instead. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971