0

私は次のように書きましたが、何らかの理由で、InstructionVal(b)の呼び出しは無効です。インテリセンスが吐き出されています:

イニシャライザメンバーNPPInstructionDef::InstructionValには()のみが許可されます

問題のあるコードは次のとおりです。

//Single Instruction Definition for Instruction Dictionary
typedef struct NPPInstructionDef
{
    const char* InstructionName;
    const unsigned char* InstructionVal[];

     NPPInstructionDef(const char* a, const unsigned char* b[]): InstructionName(a), InstructionVal()
    {
    }
}NPPInstruction;

何か案は?ありがとう。

4

1 に答える 1

1

InstructionVal( b )まず、初期化は、作成したものではなく、であると想定してInstructionVal()います。しかし、それでも、あなたが書いたものはコンパイルされるべきではありません。

これは、Cスタイルの配列が壊れているため、通常の問題であり、使用すべきではありません。あなたの定義:

unsigned char const* InstructionVal[];

の未知の長さの配列を定義します(したがって、クラス定義では不正です)unsigned char*()(値の初期化)を除いて、初期化リストでこれを初期化する方法はありません。

あなたが欲しいものは:

std::vector <unsigned char*> InstructionVal;

、およびコンストラクターは次のようになります。

NPPInstructionDef( std::string const& a,
                   std::vector <unsigned char> const& b );

、またはおそらくより可能性が高い:

template <typedef Iterator>
NPPInstructionDef( std::string const& a,
                   Iterator begin,
                   Iterator end )
    : InstructionName( a )
    , InstructionDef( begin, end )
{
}

InstructionName(これは 、もちろん、std::stringの代わりに、を想定してchar const*います。これにより、たとえば、文字列の存続期間の問題が回避され、簡単に比較できるようになります。)

于 2013-02-14T19:24:11.440 に答える