Is this possible to "using static" in Visual C++ CLI/CLR

  • Thread starter Thread starter forever a loser
  • Start date Start date
F

forever a loser

Guest
Since C# 6.0, C# programmers and developers can

using static

in their code, so static methods can be invoked directly and immediately without explicitly repeating the name of the class that provides these static methods in the code and for examples this is used to invoke the static methods of the Console, Math and String classes without repeating their names at all.

using static

is indeed a very productive and useful thing that was added to the C# programming language.

But if I need native code in addition to managed code, I need to program in C++ CLI/CLR, although I can mess up with unsafe code in C#, but still I want to benefit from the upcoming classes, functions and features in C++20 too, that in C# this will be difficult to benefit from these via P/Invoke and DllImport and unsafe code.

Is this possible to

using static

also in C++ CLI/CLR too?

I know that in C++ CLI/CLR I can use #define in a way to simulate using static.

for example:

#define Sqrt Math::Sqrt

And then in the main function I can do for example:

cout << Sqrt(2) << endl;

instead of:

cout << Math::Sqrt(2) << endl;

But I dislike this solution, because I will have to use the #define preprocessor on every static method that the managed class provides.

using static

is much shorter and readable code than the #define solution.

I will be glad if

using static

is also possible in C++ CLI/CLR.

Continue reading...
 
Back
Top