c++ - "Error: No operator "= "matches these operands"

标签 c++ vector operator-keyword operand

<分区>

我遇到了一个奇怪的问题,编译器将“=”和“!=”突出显示为错误,声称没有匹配的操作数,但我不知道如何处理。这是我的代码:

#pragma once
#include "Console.h"
#include "RandomNumber.h"
#include "Element.h"
#include "Flotsam.h"
#include "vector"
#include <list>
#include <iostream>

using namespace std;

#define NUMBER 10

int main()
{
    Console console;
    RandomNumber rnd;


    vector<Element*> flotsam;


    for(int i = 0; i < NUMBER; i++)
    {
        flotsam.push_back(new Element(rnd, console));
    }

    vector<Element>::iterator ptr;

    ptr = flotsam.begin();

    while(ptr!=flotsam.end())
    {
        ptr->printAt();
        ptr++; 
    }
    Sleep(1000);
    console.clear();

}

最佳答案

你的 vector 有不同的类型,迭代器应该是

vector<Element*>::iterator ptr;
//            ^

关于c++ - "Error: No operator "= "matches these operands",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16046984/

相关文章:

c++ - vector 迭代循环抛出错误?

java - 生成随机索引 vector

c++ - 错误 C4716 : must return a value, 由实际返回值的函数抛出

c++ - 如何(仅!)在 Visual Studio 中使用自己的构建脚本

c++ - 检测 CRT 初始化是否在注入(inject)进程中完成

c++ - 帮助识别内存泄漏

javascript - 当条件肯定为真时,Javascript < 运算符返回 false 的问题

c++ - 从内存写入时有时会损坏 TGA 文件

c++ - 链接@_Znam 和@_Znwm

Scala 等价于 F# 中的 |> 或 Clojure 中的 ->>