如果我創建了一個名爲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;
所以後來如果我想使用myForm的任何其他文件在那裏我碰巧使用IList的,就像這樣:
#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'
所以,我怎樣才能阻止將所有這些無用的和破壞性usings一種新的形式?
用記事本編碼。認真,但我假設你使用VS? – womp 2009-09-16 15:15:29
對不起,VS2008和C++/CLI - 哎呀忘了添加該信息:*) – demoncodemonkey 2009-09-16 15:18:40
爲什麼不把它們用手去除?這並不像IDE會在將來使用聲明。 – 2009-09-16 15:47:37