16

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.

4

1 に答える 1

19

ここでは、C++ の typedef がうまく機能します。

typedef System::Diagnostics::Debug DBG;
于 2010-12-01T19:22:24.710 に答える