B
Bern McCarty
I have a simple ref class in its own namespace that needs to coexist with
a legacy typedef alias for "unsigned int" in the global namespace that has
the identifier as itself. Everything compiles fine with the old MEC++ syntax,
but I cannot figure out how to write the code so that it will compile in
C++/CLI. Can someone tell me how? Here is the code in both syntaxes:
// This MEC++ code compiles just fine with VC8 using cl -c -clrldsyntax
StaticClassOldSyntax.cpp
typedef unsigned int LevelID;
namespace Test
{
public __value class LevelID
{
public private: System::UInt32 m_id;
public private: LevelID(System::UInt32 const __gc&
nlid);
public: static ::LevelID op_Explicit (LevelID const lid);
public: static LevelID op_Explicit :LevelID const nlid);
public: static bool op_Equality(LevelID const l1, LevelID
const l2);
public: static bool op_Inequality(LevelID const l1, LevelID
const l2);
public: virtual bool Equals(System::Object* obj);
public: virtual int GetHashCode();
public: virtual System::String* ToString();
};
public __abstract __sealed __gc class LevelIDs
{
public: static const ::Test::LevelID ApplicationInfo = 20u;
};
/* This fails to compile with VC8 using cl -c -clr StaticClass.cpp. It results
in:
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.42
for Microsoft (R) .NET Framework version 2.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
StaticClass.cpp
StaticClass.cpp(27) : error C2061: syntax error : identifier 'LevelID'
This diagnostic occurred in the compiler generated function 'void
Test::LevelIDs::LevelIDs(void)'
*/
typedef unsigned int LevelID;
namespace Test
{
public value class LevelID
{
internal: System::UInt32 m_id;
internal: LevelID(System::UInt32 const% nlid);
public: static explicit operator ::LevelID(LevelID const lid);
public: static explicit operator LevelID:LevelID const nlid);
public: static bool operator ==(LevelID const l1, LevelID const l2);
public: static bool operator !=(LevelID const l1, LevelID const l2);
public: virtual bool Equals(System::Object ^ obj) override;
public: virtual int GetHashCode() override;
public: virtual System::String^ ToString() override;
};
public ref class LevelIDs abstract sealed
{
public: initonly static ::Test::LevelID ApplicationInfo = static_cast<::Test::LevelID>(20u);
};
}
a legacy typedef alias for "unsigned int" in the global namespace that has
the identifier as itself. Everything compiles fine with the old MEC++ syntax,
but I cannot figure out how to write the code so that it will compile in
C++/CLI. Can someone tell me how? Here is the code in both syntaxes:
// This MEC++ code compiles just fine with VC8 using cl -c -clrldsyntax
StaticClassOldSyntax.cpp
typedef unsigned int LevelID;
namespace Test
{
public __value class LevelID
{
public private: System::UInt32 m_id;
public private: LevelID(System::UInt32 const __gc&
nlid);
public: static ::LevelID op_Explicit (LevelID const lid);
public: static LevelID op_Explicit :LevelID const nlid);
public: static bool op_Equality(LevelID const l1, LevelID
const l2);
public: static bool op_Inequality(LevelID const l1, LevelID
const l2);
public: virtual bool Equals(System::Object* obj);
public: virtual int GetHashCode();
public: virtual System::String* ToString();
};
public __abstract __sealed __gc class LevelIDs
{
public: static const ::Test::LevelID ApplicationInfo = 20u;
};
/* This fails to compile with VC8 using cl -c -clr StaticClass.cpp. It results
in:
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.42
for Microsoft (R) .NET Framework version 2.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
StaticClass.cpp
StaticClass.cpp(27) : error C2061: syntax error : identifier 'LevelID'
This diagnostic occurred in the compiler generated function 'void
Test::LevelIDs::LevelIDs(void)'
*/
typedef unsigned int LevelID;
namespace Test
{
public value class LevelID
{
internal: System::UInt32 m_id;
internal: LevelID(System::UInt32 const% nlid);
public: static explicit operator ::LevelID(LevelID const lid);
public: static explicit operator LevelID:LevelID const nlid);
public: static bool operator ==(LevelID const l1, LevelID const l2);
public: static bool operator !=(LevelID const l1, LevelID const l2);
public: virtual bool Equals(System::Object ^ obj) override;
public: virtual int GetHashCode() override;
public: virtual System::String^ ToString() override;
};
public ref class LevelIDs abstract sealed
{
public: initonly static ::Test::LevelID ApplicationInfo = static_cast<::Test::LevelID>(20u);
};
}