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;

したがって、たまたま 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'

では、新しいフォームがこれらの役に立たない破壊的な使用をすべて追加するのをどのように停止できますか?

4

2 に答える 2

2

Visual Studio のフォーム テンプレートを変更できます。さらに読むには、以下をご覧ください。

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

于 2009-09-16T15:18:43.980 に答える
2

使用する特定の言語の ItemTemplates ディレクトリにある zip ファイルを編集することで、Visual Studio が使用する既定のテンプレートを変更できます。

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

C# テンプレートがある場所です。C++ テンプレートは同様のディレクトリにあると想定していますが、C++ が便利な VS インスタンスがインストールされていません。

于 2009-09-16T15:19:10.670 に答える