17

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.

David Yaw
  • 27,383
  • 4
  • 60
  • 93

1 Answers1

20

A C++ typedef will do the trick here.

typedef System::Diagnostics::Debug DBG;
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454