没有匹配函数来调用 std::vector<float>

No matching function to call to std::vector<float>

本文关键字:vector gt lt float std 函数 调用      更新时间:2023-10-16

我正在编写一个从3D世界到2D投影的代码,当我试图推回矢量中的坐标时,它给了我一个错误,即没有匹配函数可以调用std::vector。

#include <X11/Xlib.h>
#include "draw.h"
#include "points.h"
#include "unistd.h"
#include <math.h>
#include <vector>

void draw(Display* d, Window w, GC gc)
{
    std::vector<float> xpoints;
    xpoints.push_back (-1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0);
    std::vector<float> ypoints;
    ypoints.push_back (1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0);
    std::vector<float> zpoints;
    zpoints.push_back (-1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0);
    for (;;)
    {
        XClearWindow(d, w);
        for (unsigned int c = 0; c < xpoints.size(); c++)
        {
            XDrawLine(d, w, gc, xpoints.at(c), ypoints.at(c), xpoints.at(c+1), ypoints.at(c+1));
        }
        XFlush(d);
        usleep(16666);
    }
}

不能使用push_back:同时推送多个值

xpoints.push_back (-1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0);

如果您使用c++11,您应该直接初始化您的矢量:

std::vector<float> xpoints{-1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0};

只需包含向量头:

#include <vector>