gpt4 book ai didi

c++ - 错误 :expected unqualified-id before '=' token

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:27:39 24 4
gpt4 key购买 nike

我在使用 g++ 时不断收到此错误。

这是有问题的代码行:

Register register = new Register(til_amt, num_ones);

这是标题定义:

Register(int, int);

这是实现定义:

Register::Register(int amt, int ones)
{
init();

til_amt += amt;
num_ones += ones;
}

init() 函数是内联定义的,只是将字段设置为 0。我已将问题隔离到这些代码行,并且我在 stackoverflow/google 上进行了全面搜索,但似乎无法解决问题.我什至尝试将对象实例化分成两行,但这也没有用。

最佳答案

register 是关键字。它不能用作变量。

来自 C++ 标准:

7.1.1 Storage class specifiers [dcl.stc]

1 The storage class specifiers are

   storage-class-specifier:        register      static      thread_local      extern      mutable

关于c++ - 错误 :expected unqualified-id before '=' token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34101691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com