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

1

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.

Crippen answered 1/12, 2010 at 19:17 Comment(0)
G
20

A C++ typedef will do the trick here.

typedef System::Diagnostics::Debug DBG;
Garcia answered 1/12, 2010 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.