没有运算符"="匹配这些操作数 [英] No operator "=" matches these operands

查看:526
本文介绍了没有运算符"="匹配这些操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这一定是很愚蠢的,但是我在使用此代码时遇到了错误.

So this must be something really silly, but I'm getting an error with this code.

出了什么问题,操作数< ;,>也不起作用.一个人使用向量的方式不同吗?当我尝试y.at(1)= 10;它说表达式必须具有类类型...?

What could be going wrong, the operands <, > also don't work. Does one use vectors differently? When I try y.at(1) = 10; it says expression must have class type...?

#include "stdafx.h"
#include <iostream>
#include "time.h"
#include <vector>


int main()
{
    using namespace std;
    const long long l = 100000;

    vector <int> y[l];
    long long x[l];

    y[0] = 10; // Test statement results in Error.

//for (long i = 0;i < l;i++) {
    //  y.at(i) = i;//rand() % 100;
    //  x[i] = rand() % 100;
    //}



    clock_t t = clock();

    for (long long i = 0;i < l;i++) {
        long long r;
        r = y[i] ^ ((x[i]^y[i]) & -(x[i] < y[i]));
        /*if (x[i] < y[i]) {
            r = x[i];
        }
        else {
            r = y[i];
        }*/

    }

    t = clock() - t;

    printf("It took %d ms ", t);

return 0;

}

对于上下文,我正在尝试测试运行时间.首先使用std :: array,但似乎不适用于大型数组,因此我决定尝试使用向量.

For context I'm trying to test for run times. Was using std::array at first, but it seems like that doesn't work with large array sizes, so I decided to try out vectors.

已使用 http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/C-Tutorial-A-Beginners-Guide-to-stdvector-Part-1.htm 作为参考,但看起来尽管我做的是完全相同的事情,但还是有问题.

Used http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/C-Tutorial-A-Beginners-Guide-to-stdvector-Part-1.htm as a reference, but it seems like although I'm doing the exact same thing, something is not working.

推荐答案

这是一种非常常见的打字错误,

This is a quite common typo, writing

std::vector<int> y[10];

声明一个由10个空向量组成的数组.要具有10个元素的向量,您需要

declares an array of 10 empty vectors. To have a vector of 10 elements you need

std::vector<int> y(10);

相反.

并非只有您一个人认为犯此错误时的错误消息有些含糊...不幸的是,这是一个缺少C ++的领域(现在不确定,但我记得有些公司靠它谋生只是从VC ++解密C ++错误消息.)

You're not alone in thinking that the error message when making this mistake is somewhat cryptic... this is an area in which unfortunately C++ is lacking (not sure now, but I remember that there were companies making a living on just deciphering C++ error messages from VC++).

这篇关于没有运算符"="匹配这些操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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