c++-cliusing-directives

Using directive to specify class alias in C++/CLI


In C#, there are three types of using directives:

using System; // Specify Namespace
using Diag = System.Diagnostics; // Specify Namespace Alias
using DBG = System.Diagnostics.Debug;  // Specify Class Alias

In C++/CLI, I know the equivalents to the first two:

using namespace System;
namespace Diag = System::Diagnostics;

Is there any way to do the third one in C++/CLI?

Doing namespace DBG = System::Diagnostics::Debug; gives error C2879: 'System::Diagnostics::Debug' : only an existing namespace can be given an alternative name by a namespace alias definition

The only alterntive I've come up with is #define DBG System::Diagnostics::Debug, but I'd prefer a proper using directive, if available.


Solution

  • A C++ typedef will do the trick here.

    typedef System::Diagnostics::Debug DBG;