c ++编译“错误:'='标记之前的预期构造函数,析构函数或类型转换" [英] c++ compiling "error: expected constructor, destructor, or type conversion before '=' token "

查看:33
本文介绍了c ++编译“错误:'='标记之前的预期构造函数,析构函数或类型转换"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

位于同一文件"foo.h"中的非常简单的代码:

Very simple codes located in the same file 'foo.h':

class Xface
{
  public:
    uint32_t m_tick;
    Xface(uint32_t tk)
    {
      m_tick=tk;
    }
}

std::map<uint32_t, Xface*> m;

Xface* tmp;

tmp = new Xface(100);  **//Error**
m[1] = tmp;  **//Error**

tmp = new Xface(200);  **//Error**
m[2] = tmp;  **//Error**

错误是错误:'='令牌之前的预期构造函数,析构函数或类型转换每次作业.

推荐答案

C ++不是脚本语言.您可以在可执行代码块的边界之外声明项目,但不能进行任何处理.尝试将错误代码移入这样的函数中:

C++ is not a scripting language. You can declare items outside the bounds of an executable block of code, but you cannot do any processing. Try moving the erroring code into a function like this:

int main()
{
    std::map<uint32_t, Xface*> m;

    Xface* tmp;

    tmp = new Xface(100);  **//Error**
    m[1] = tmp;  **//Error**

    tmp = new Xface(200);  **//Error**
    m[2] = tmp;  **//Error**
}

这篇关于c ++编译“错误:'='标记之前的预期构造函数,析构函数或类型转换"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆