2009-09-16 46 views
1

如果我創建了一個名爲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一種新的形式?

+0

用記事本編碼。認真,但我假設你使用VS? – womp 2009-09-16 15:15:29

+0

對不起,VS2008和C++/CLI - 哎呀忘了添加該信息:*) – demoncodemonkey 2009-09-16 15:18:40

+0

爲什麼不把它們用手去除?這並不像IDE會在將來使用聲明。 – 2009-09-16 15:47:37

回答

2

您可以更改的Visual Studio使用通過編輯的ItemTemplate目錄中的zip文件,您使用的特定語言的默認模板。

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033

是在C#模板。我假設C++模板將在類似的目錄中,但我沒有用C++方便地安裝VS實例。

+0

VC的是在:C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplates \ VisualC \ 1033然而,只有4個zip文件 - HelpTest,OrderedTest,SimpleUnitTest和UnitTestWizard。沒有Form.zip或任何遠程有用的東西:( – demoncodemonkey 2009-09-16 15:24:00

+0

呵呵。有趣的。這個目錄看起來很有希望:C:\ Program Files \ Microsoft Visual Studio 9.0 \ VC \ vcprojectitems \ Code ...除了code.vsdir文件似乎是指向一些註冊表鍵...讓我跟着他們... – womp 2009-09-16 15:44:29

+0

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/86b9d540-376f-4cb7-bd4f-f401e0fba7b3似乎是在正確的方向。不知道編輯「hfile.h」是否會解決你的問題。 – womp 2009-09-16 15:48:54

2

您可以修改Visual Studio的表單模板。對於進一步的閱讀,看看:

http://msdn.microsoft.com/en-us/library/ms185319(VS.80).aspx

+0

對不起,我沒有看到它適用於表單 - 它似乎只是談論項目。你能解釋一下如何使用這種方法來改變表單模板嗎? – demoncodemonkey 2009-09-16 15:26:12

+0

項目模板應位於: 「C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplates \ VisualC \ 1033」 但是,建議您創建自己的自定義表單模板,而不是修改默認表單模板。你可以在這裏找到如何創建你自己的模板的說明: http://www.dev102.com/2008/07/24/visual-studio-item-templates/ – 2009-09-17 08:16:23

+0

謝謝,但在這種情況下,我確實想要修改默認的一個。你爲什麼會說它建議創建一個自定義的? – demoncodemonkey 2009-09-17 08:43:43

相關問題