簡體   English   中英

沒有匹配的函數來調用 std::vector<float>

[英]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>

沒有匹配的 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> 沒有匹配的 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..> 沒有匹配的函數來調用&#39;merge(std :: vector <int> &,std :: vector <int> &) 傳遞std向量作為參考:沒有匹配的函數來調用 沒有用於調用std :: vector的匹配函數 <std::tuple> 推回 錯誤:沒有匹配的 function 調用 'recherche(std::vector &gt;&amp;, std::vector &gt;::iterator, std::vector &gt;::iterator, const char [10])' 錯誤:沒有匹配的 function 調用 'std::vector::erase(int)' 沒有匹配的函數調用&#39;std::vector &gt;::push_back(char&amp;)&#39; C ++線程與以std :: vector為參數的函數調用不匹配 指針混淆導致“沒有匹配的 function 調用 std::vector”?
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM