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

时间:2016-05-04 09:53:40

标签: c++ vector

我正在为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);
    }
}

2 个答案:

答案 0 :(得分:3)

您无法使用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};

答案 1 :(得分:0)

只需包含矢量标题:

#include <vector>