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

标签 c++ linux g++

我在使用 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/

相关文章:

linux - linux下访问root文件非常慢

linux - 在不启动 Ubuntu 终端的情况下执行我的 Shell 和 Bash 脚本

gcc - Makefile无缘无故删除目标文件

c++ - g++ 与旧代码的旧目标文件链接良好

没有运算符定义的 C++ 失败

iphone - Phonegap - C++ 库

c++ - 你能取消引用整数文字吗?

linux - 默认的 Puppet 用户名和密码是什么?

c++ - 如何在继承级别为容器类做可见的嵌套类?

c++ - 基于指针的查询