简体   繁体   中英

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

I am writing a code for 3D world to 2D projection and as i try to push back coordinates in my vectors it gives me this error that there is no matching function to call to 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);
    }
}

You cannot push multiple values at once using push_back :

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

If you are using c++11 you should directly initialize your vector:

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

只需包含矢量标头:

#include <vector>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM