如何使用命名空间System :: Collections来停止新表单
-
07-07-2019 - |
题
如果我创建一个名为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;
甚至不需要这些,因为精彩的表单设计师总是完全限定其对象。
标有这一个的那个特别讨厌,因为它打破了我的构建。这是因为我在整个地方使用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'
那么,我怎样才能阻止新表格添加所有这些无用且具有破坏性的用途?
解决方案
您可以通过编辑ItemTemplates目录中针对您使用的特定语言的zip文件来更改Visual Studio使用的默认模板。
C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplates \ CSharp \ Code \ 1033
是C#模板的所在。我假设C ++模板将在类似的目录中,但我没有安装C ++的VS实例。
其他提示
您可以修改Visual Studio的表单模板。如需进一步阅读,请查看:
不隶属于 StackOverflow