myForm という新しいフォームを作成すると、myForm.h の上部は次のようになります。
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections; //<<<< THIS ONE
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
優れたフォーム デザイナーは常にそのオブジェクトを完全に修飾するため、これらのいずれも必要ありません。
THIS ONE でマークされたものは、私のビルドを壊してしまうため、特に厄介です。これは、私が IList の一般的な形式をあらゆる場所で使用しているためです。私はそれをとても気に入っているので、次のように stdafx.h に入れています。
using System::Collections::Generic::IList;
したがって、たまたま IList を使用している他のファイルから myForm を使用する場合は、次のようにします。
#include "StdAfx.h"
#include "ABC.h"
#include "myForm.h"
ABC::ABC()
{
IList<int>^ myList;
...
}
その後、コンパイルに失敗します:
1>.\ABC.cpp(7) : error C2872: 'IList' : ambiguous symbol
1> could be 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Collections::Generic::IList'
1> or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Collections::IList'
1>.\ABC.cpp(7) : error C2872: 'IList' : ambiguous symbol
1> could be 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Collections::Generic::IList'
1> or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Collections::IList'
では、新しいフォームがこれらの役に立たない破壊的な使用をすべて追加するのをどのように停止できますか?