简体   繁体   English

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

[英]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.我正在编写 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);
    }
}

You cannot push multiple values at once using push_back :您不能使用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:如果您使用的是c++11您应该直接初始化您的向量:

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

只需包含矢量标头:

#include <vector>

没有匹配的 function 调用 'std::vector <std.. '< div><div id="text_translate"><p> 我正在解决的问题是:我必须采用<strong>T</strong>测试用例。 For each test case I have to take string as an input, then I need to arrange the input string as: <em>string at even position {double space} string at odd position</em> (example: <em>input</em> - StackOverflow, <em>output</em> - <strong>Sakvrlw</strong> <strong>tcOefo</strong> ). 我编写了以下代码,其中我为所有测试用例获取输入并将其存储在向量中。 然后我将 vector 的元素分配给另一个声明的 string s。</p><pre> #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;vector&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;string&gt; using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int T,i; cout &lt;&lt; "Enter no. of test cases: "; cin &gt;&gt; T; vector&lt;string&gt; v; vector&lt;string&gt; odd; vector&lt;string&gt; even; string str; for(int i=0; i&lt;T; i++){ cin &gt;&gt; str; v.push_back(str); } string s; for(i=0; i&lt;v.size(); i++){ s = v.at(i); for(i=0; i&lt;s.size(); i++){ if(i==0){ even.push_back(s[i]); //*This is where I am getting error*. }else if(i==1){ odd.push_back(s[i]); }else{ if(i%2==0){ even.push_back(s[i]); }else{ odd.push_back(s[i]); } } } for(i=0; i&lt;even.size(); i++){ cout &lt;&lt; even.at(i); } cout &lt;&lt; " "; for(i=0; i&lt;odd.size(); i++){ cout &lt;&lt; odd.at(i); } cout &lt;&lt; endl; even.clear(); odd.clear(); s.clear(); } return 0; }</pre><p> 在编译上面的代码时,我得到"no matching error for call std::vector..." 。 <strong><em>我到底做错了什么?</em></strong></p></div></std..> - no matching function for call to 'std::vector<std.. '

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:没有匹配的 function 调用 'std::vector<float> ::push_back(std::vector<float> &amp;) 常量'</float></float> - error: no matching function for call to 'std::vector<float>::push_back(std::vector<float>&) const' 没有匹配的 function 调用 'std::vector <std.. '< div><div id="text_translate"><p> 我正在解决的问题是:我必须采用<strong>T</strong>测试用例。 For each test case I have to take string as an input, then I need to arrange the input string as: <em>string at even position {double space} string at odd position</em> (example: <em>input</em> - StackOverflow, <em>output</em> - <strong>Sakvrlw</strong> <strong>tcOefo</strong> ). 我编写了以下代码,其中我为所有测试用例获取输入并将其存储在向量中。 然后我将 vector 的元素分配给另一个声明的 string s。</p><pre> #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;vector&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;string&gt; using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int T,i; cout &lt;&lt; "Enter no. of test cases: "; cin &gt;&gt; T; vector&lt;string&gt; v; vector&lt;string&gt; odd; vector&lt;string&gt; even; string str; for(int i=0; i&lt;T; i++){ cin &gt;&gt; str; v.push_back(str); } string s; for(i=0; i&lt;v.size(); i++){ s = v.at(i); for(i=0; i&lt;s.size(); i++){ if(i==0){ even.push_back(s[i]); //*This is where I am getting error*. }else if(i==1){ odd.push_back(s[i]); }else{ if(i%2==0){ even.push_back(s[i]); }else{ odd.push_back(s[i]); } } } for(i=0; i&lt;even.size(); i++){ cout &lt;&lt; even.at(i); } cout &lt;&lt; " "; for(i=0; i&lt;odd.size(); i++){ cout &lt;&lt; odd.at(i); } cout &lt;&lt; endl; even.clear(); odd.clear(); s.clear(); } return 0; }</pre><p> 在编译上面的代码时,我得到"no matching error for call std::vector..." 。 <strong><em>我到底做错了什么?</em></strong></p></div></std..> - no matching function for call to 'std::vector<std.. ' 没有匹配的函数来调用&#39;merge(std :: vector <int> &,std :: vector <int> &) - No matching function for call to 'merge(std::vector<int>&, std::vector<int>&) 传递std向量作为参考:没有匹配的函数来调用 - Passing std vector as reference: no matching function to call 没有用于调用std :: vector的匹配函数 <std::tuple> 推回 - no matching function for call to std::vector<std::tuple> push_back 错误:没有匹配的 function 调用 'recherche(std::vector &gt;&amp;, std::vector &gt;::iterator, std::vector &gt;::iterator, const char [10])' - error: no matching function for call to ‘recherche(std::vector >&, std::vector >::iterator, std::vector >::iterator, const char [10])’ 错误:没有匹配的 function 调用 'std::vector::erase(int)' - error: no matching function for call to ‘std::vector::erase(int)’ 没有匹配的函数调用&#39;std::vector &gt;::push_back(char&amp;)&#39; - no matching function for call to 'std::vector >::push_back(char&)' C ++线程与以std :: vector为参数的函数调用不匹配 - C++ threads not matching function call with std::vector as argument 指针混淆导致“没有匹配的 function 调用 std::vector”? - Pointer confusion causing "no matching function call for std::vector"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM