![](/img/trans.png)
[英]error: no matching function for call to 'std::vector<float>::push_back(std::vector<float>&) const'
[英]No matching function to call to std::vector<float>
我正在編寫 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.