2017-07-04 57 views
0

C++フォームアプリケーションを作成すると、あいまいなシンボルエラーが発生するようになりました。しかし、私はそれが以前からうまくコンパイルされていたが、何かを変更した可能性があるかどうかは不明です。Windows Formsアプリケーションで不明瞭なシンボルが多く表示される

なた自身がエラー:私のフォームは、これらのファイルのいずれにも含まれていないため

1>Application.cpp 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): error C2872: 'IDropTarget': ambiguous symbol 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\oleidl.h(3508): note: could be 'IDropTarget' 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): note: or  'System::Windows::Forms::IDropTarget' 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): error C2872: 'IServiceProvider': ambiguous symbol 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\servprov.h(98): note: could be 'IServiceProvider' 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): note: or  'System::IServiceProvider' 
1>main.cpp 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): error C2872: 'IDropTarget': ambiguous symbol 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\oleidl.h(3508): note: could be 'IDropTarget' 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): note: or  'System::Windows::Forms::IDropTarget' 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): error C2872: 'IServiceProvider': ambiguous symbol 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\servprov.h(98): note: could be 'IServiceProvider' 
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): note: or  'System::IServiceProvider' 

は、私は、これは奇妙な見つけ、私はそれが名前空間に起因するものだと仮定します。私はちょうどこれが実際にどこから来ているのか分かりません。ここで

は情報のための私の形式である:私のフォームに関する

#include <Windows.h> 

using namespace System; 
using namespace System::ComponentModel; 
using namespace System::Collections; 
using namespace System::Windows::Forms; 
using namespace System::Data; 
using namespace System::Drawing; 

public ref class CFormController : public Form 
{ 
public: 
    CFormController(void) 
    { 
     InitializeComponent(); 
    } 
    ~CFormController() 
    { 
     delete components; 
    } 

    System::ComponentModel::Container ^components; 

    void InitializeComponent(void) 
    { 
     this->components = gcnew System::ComponentModel::Container(); 
     this->Size = System::Drawing::Size(300, 300); 
     this->Text = L"FormController"; 
     this->Padding = System::Windows::Forms::Padding(0); 
     this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
    } 
}; 

唯一の他の情報は別のクラスです。 Thatsはそれを表示または非表示にするためにのみ使用されました。

私は「...名前空間を使用する」前に、その人で同様の問題は、Windowsのヘッダーが含まれていませんでしたが、私はあなたが見て、それはあなたが輸入している

+0

** ** ** C++ではありません。これはC++/CLIです。それに応じてタグを付けてください。 –

+0

私の謝罪、私は余分なタグが必要であることを知らなかった –

+0

_extra_タグは必要ありませんでした。私が前に言及したように - これは** C++ではないので、C++タグは削除する必要があり、C++ - CLIタグで置き換えられました。 –

答えて

1

全く違いはありませんでしたとしてインクルードには、追加シンボルをグローバル名前空間に衝突させます。

投稿したコードは、コンパイルユニットに含まれる最初のファイルであれば問題ありません。そうでない場合(たとえば、投稿したヘッダファイルの前に別のヘッダファイルをインクルードした場合)、windows.hをインクルードすると、グローバル名前空間に既に存在するWinFormsタイプを持つことができ、C2872が発生します。

紛争を避けるために、usingステートメントまたはwindows.h includeを名前空間に移動することができます。例:

namespace Win32 { 
#include "windows.h" 
} 

または

namespace ProjectName { 

using namespace System; 
...... 
} 

それとも、本当に、グローバル名前空間に型をインポートする2つのcppのファイルにコードを分離し、1度に1つずつをインポートする場合。

-1

C++/CLIは、多くのC#名前空間を「使用」しているときはいつでも、シンボルの競合が発生することで有名です。明らかに、SystemとSystem :: Windows :: Formsの間に矛盾があります。後者の "using"宣言を削除し、System :: Windows :: Forms ::の接頭辞を付けてこの名前空間のシンボルを指定してください。私はこれが王の痛みであることを知っていますが、私が知る限り、他の回避策はありません。

私はSystem :: Collections :: Genericからクラスが必要なときはいつでもこの問題に直面します。

関連する問題