Luka Jankovic Luka Jankovic - 1 month ago 17
C++ Question

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);
}
}

Answer

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};
Comments