2

編集: 私のプログラミング言語は C++ であり、私の IDE は Qt Creator であることを忘れていました。

マップの参照されたベクトルに要素を追加する際に問題が発生する理由がわかりません (つまり、機能する場合と失敗する場合があります)。

例えば:

class C_html4_tags {
     public:
       C_html4_tags();
       //.......

       typedef std::vector<S_html_attr_value> TYPE_attr_values;

    //.....
};

//...
C_html4_tags::C_html4_tags() {

//........
map<S_browser, TYPE_attr_values> attr_supported_attr_values_map;
S_browser dummy_browser; //a fake browser key for referencing a fully Html 4.01-compliant supported attr values list
dummy_browser.name = "Dummy";

//.....
TYPE_attr_values& attr_supported_attr_values = attr_supported_attr_values_map[dummy_browser];

//......
**attr_supported_attr_values = attr_supported_attr_values_map[dummy_browser];**

//...
**attr_supported_attr_values.clear();
  attr_supported_attr_values_map.clear();**

//......
**attr_supported_attr_values = attr_supported_attr_values_map[dummy_browser];**

//...
**attr_supported_attr_values.clear();
attr_supported_attr_values_map.clear();**

}

太字の行をさまざまな属性で複数回実行しますが、それらの間にほとんど違いはありませんが、この 1 つの属性 (a_tabindex_attr) に到達するまで問題はありません。IDE は通常実行時に何も問題を報告しません ("プログラムは予期せず終了しました。」ただし、デバッグ時に次のように報告されるようになりました。

受信信号

オペレーティング システムから信号を受信したため、下位が停止しました。

信号名:SIGSEGV 信号の意味:セグメンテーション違反

そして、バックトレースは、これを行うコード行で、上記の属性を指しています。

attr_supported_attr_values.clear();

ここで、コードにデバッグ用の cout 行をいくつか追加した後、何らかの理由で、次のことを行った後でも何が起こっているかを知りました。

attr_supported_attr_values.push_back(attr_value);

次のマッピングされた値が返されるベクトル オブジェクト:

attr_supported_attr_values = attr_supported_attr_values_map[dummy_browser];

S_html_attr_value オブジェクトを参照されたベクトルに push_back しても、実際には変更されていません。これがなぜなのかはわかりません。これより前に、他の属性のコードの束でまったく同じことを問題なく行っているためです。 attr_supported_attr_values へのオブジェクト (これは、'dummy_browser' の返されたマップされた値への参照です)。マップの内部マップ値オブジェクトのサイズを (マップの反復子を使用して) 出力したため、push_back() の呼び出し後は 0 だったので、事実としてこれを知っています。ただし、さらに奇妙なのは、push_back() の呼び出し後に attr_supported_attr_values.size() も出力したことです。これは 1 でした。両方とも同じオブジェクトであるはずなのに、どうしてでしょうか??

ノート:

私が話していることの完全なコードは以下のとおりです (または、少なくとも属性コードからデバッグ ステートメントを除いたもの...):

//a_tabindex_attr:
attr_desc = "Specifies the position of an <a> element in the\n"
            "tabbing order for the current document.\n"
            "The tabbing order defines the order in which\n"
            "elements will receive focus when navigated by\n"
            "the user via the keyboard. The tabbing order\n"
            "may include elements nested within other elements.\n"
            "Elements that may receive focus based on tabindex\n"
            "adhere to the following rules:\n\n"
            "1. Those elements that support this attribute and\n"
            "assign a positive value to it are navigated first.\n"
            "Navigation proceeds from the element with the\n"
            "lowest tabindex value to the element with the\n"
            "highest value. Values need not be sequential\n"
            "nor must they begin with any particular value.\n"
            "Elements that have identical tabindex values\n"
            "should be navigated in the order they appear\n"
            "in the character stream.\n"
            "2. Those elements that do not support this\n"
            "attribute or support it and assign it a value\n"
            "of \"0\" are navigated next. These elements are\n"
            "navigated in the order they appear in the\n"
            "character stream.\n"
            "3. Elements that are disabled do not participate\n"
            "in the tabbing order.";
attr_supported_attr_values = attr_supported_attr_values_map[dummy_browser];

attr_value_desc = "A number you specify for the tab index/order.\n"
                  "It must be a value between 0 and 32767.";
attr_value_content = "<i>number</i>";
attr_value = C_html4_attributes_obj.getAttrValue(attr_value_desc, attr_value_content,
                                                 attr_value_supported_browsers,
                                                 attr_value_required, attr_value_deprecated,
                                                 attr_value_notes, attr_value_tips);
attr_value.is_relative = true;
attr_supported_attr_values.push_back(attr_value);

try {
   N_init_class_members::initAttr(C_html4_attributes::attr_tabindex, a_tabindex_attr, attr_desc,
                                  attr_supported_browsers, attr_supported_attr_values_map, attr_required,
                                  attr_deprecated, attr_notes, attr_tips);
}

catch (const char* exc) {
     string exc_str = "Error! Call to N_init_class_members::initAttr() from\n"
                      "constructor of C_html4_tags class. That function\n"
                      "reported the following exception:\n\n";
     exc_str += exc;
     throw (exc_str.c_str()); //re-throw exception
}
a_tabindex_attr.is_standard_attr = true;
a_tabindex_attr.is_optional_attr = true;

//cleanup from attribute operations so we can begin working on the next attribute:
C_html4_attributes_obj.clear(); //wipes the slate clean for all the supported attributes' properties except content
attr_desc.clear();
attr_supported_attr_values.clear();
attr_supported_attr_values_map.clear();
attr_value_desc.clear();
attr_value_content.clear();
4

0 に答える 0