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' 之前缺少 ')'

错误 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 回答