1

私がこのc++cliコードを持っているとき:

#pragma managed
ref class mcSessions: ConcurrentDictionary <String ^, mcSession^> 
{  //<---- warning here
private:
   static mcSessions ^g_Sessions;
       TimeSpan MaxIdleTime;
   mcSessions (TimeSpan newMaxIdleTime);
public:
    static void Initialize (long MaxIdleMinutes);
        static void Shutdown ();
        static void CreateSession (String ^&SessionId);
        static void RunInSession (String ^SessionId, String ^Command);
        static void RemoveSession (String ^SessionId);
};

最初の{で警告C4538が表示されます。誰かがこれが起こる理由とそれが警告するものの手がかりを持っていますか、またはこれはこの質問の状況のようにコンパイラのバグでもあります:C ++/CLIでの不適切なコンパイル警告のようです

それらは多少関連しているように見えますが、私はGroupオブジェクトではなく、を持っていますConcurrentDictionary。.NET4.0フレームワークを対象としたVisualStudio2010を使用しており、/clrコンパイラフラグをオンにしてコンパイルしています。

正確なエラーメッセージは次のとおりです。

1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=System::Collections::Concurrent::ConcurrentDictionary::Node ^,
1>              dimension=1
1>          ]
1>          This diagnostic occurred while importing type 'System::Collections::Concurrent::ConcurrentDictionary ' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=int,
1>              dimension=1
1>          ]
1>          This diagnostic occurred while importing type 'System::Collections::Concurrent::ConcurrentDictionary ' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=System::Collections::Concurrent::ConcurrentDictionary<TKey,TValue>::Node ^,
1>              dimension=1
1>          ]
1>          d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25) : see reference to class generic instantiation 'System::Collections::Concurrent::ConcurrentDictionary<TKey,TValue>' being compiled
1>          d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25) : see reference to class generic instantiation 'System::Collections::Concurrent::ConcurrentDictionary<TKey,TValue>' being compiled
1>          with
1>          [
1>              TKey=System::String ^,
1>              TValue=IamPowershell::mcSession ^
1>          ]
1>          This diagnostic occurred while importing type 'System::Collections::Concurrent::ConcurrentDictionary::Node ' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=int,
1>              dimension=1
1>          ]
1>          This diagnostic occurred while importing type 'System::Collections::Concurrent::ConcurrentDictionary::Node ' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=System::Collections::Concurrent::ConcurrentDictionary<System::String ^,mcSession ^>::Node ^,
1>              dimension=1
1>          ]
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=int,
1>              dimension=1
1>          ]
1>
4

2 に答える 2

1

前述のように、問題はConcurrentDictionaryの不安定なメンバーです。ただし、表示したコードから、ConcurrentDictionaryから継承する必要はありません。

一般に、汎用で再利用可能なコレクションクラスを作成する場合にのみ、コレクションクラスから継承する必要があると思います。ここではそうではないようです。mcSessionクラスに非常に固有であり、単純な収集ロジックではなく、おそらくビジネスロジックを持っているようです。

このようにクラスを宣言した場合、それは機能しますか?

ref class mcSessions
{
private:
    static ConcurrentDictionary<String^, mcSession^>^ g_Sessions;
    TimeSpan MaxIdleTime;
    mcSessions (TimeSpan newMaxIdleTime);
public:
    static void Initialize (long MaxIdleMinutes);
    static void Shutdown ();
    static void CreateSession (String ^&SessionId);
    static void RunInSession (String ^SessionId, String ^Command);
    static void RemoveSession (String ^SessionId);
};

編集:またはこのように?

ref class mcSessions
{
private:
    static mcSessions^ g_Sessions;// static session manager
    ConcurrentDictionary<String^, mcSession^>^ SessionList; // instance variable on g_Sessions
    TimeSpan MaxIdleTime;
    mcSessions (TimeSpan newMaxIdleTime);
public:
    static void Initialize (long MaxIdleMinutes);
    static void Shutdown ();
    static void CreateSession (String ^&SessionId);
    static void RunInSession (String ^SessionId, String ^Command);
    static void RemoveSession (String ^SessionId);
};
于 2013-02-07T17:01:12.627 に答える
0

@HansPassantが質問のコメントで述べたように、彼は正しいです。メンバーは確かに不安定です(私は愚かです、それをチェックしたかもしれません:S)とにかくそれが答えになるはずです。ありがとう私はそれが今解決したと思います。

于 2013-02-07T14:55:50.500 に答える