1
typedef struct {
    index_tree_node node;
    uint32_t number;
    lzma_vli block_number_base;
    index_tree groups;
    lzma_vli record_count;
    lzma_vli index_list_size;
    lzma_stream_flags stream_flags;
    lzma_vli stream_padding;
} index_stream;

以下は機能です:

static void
index_cat_helper(const index_cat_info *info, index_stream *this)   //problem line
{
    index_stream *left = (index_stream *)(this->node.left);
    index_stream *right = (index_stream *)(this->node.right);

    if (left != NULL)
        index_cat_helper(info, left);

    this->node.uncompressed_base += info->uncompressed_size;
    this->node.compressed_base += info->file_size;
    this->number += info->stream_number_add;
    this->block_number_base += info->block_number_add;
    index_tree_append(info->streams, &this->node);

    if (right != NULL)
        index_cat_helper(info, right);

    return;
}

エラー:

エラー C2143: 構文エラー: 'this' の前に ')' がありません

error C2447: '{' : 関数ヘッダーがありません (古いスタイルの正式リスト?)

これらのエラーの原因を探しています。

4

2 に答える 2

6

this変数の名前として使用できないC++ キーワードです。これは、そのインスタンス内からクラスのインスタンスへのポインタを表します。

例(this実際にはここでは省略できますが)

struct Foo
{
  void foo() const { this->bar(); }
  void bar() const {}
  void step() { this->counter++; }
  int counter = 0; // don't worry, C++11 initialization
};

別の名前が必要です。

于 2013-03-07T07:18:34.520 に答える
1

C コードのように見えるものを C++ としてコンパイルしようとしています。C と C++ は異なる言語であるため、これにより問題が発生することに注意してください (たとえばmalloc、C コードでは推奨されていない の戻り値をキャストする必要があります)。

適切なことは、C++ コンパイラではなく、C コンパイラを使用することです。

于 2013-03-07T07:24:40.617 に答える