ERROR: no match for 'operator<<" in 'std::cout

前端 未结 5 1293
孤城傲影
孤城傲影 2021-01-22 13:32

I realize this error is usually due to some syntax or type issues but I am not sure how to solve this problem. I think it may do with the type of findRt.

vector&         


        
5条回答
  •  灰色年华
    2021-01-22 13:45

    You'll have to create an overloaded version of operator<< for std::cout. It would look something like the following:

    ostream& operator<<(ostream& out, const vector& triangles);
    

    and at the end of the function, you simply do a return out; in order to return the std::ostream object out that was passed as the first argument (in your case that will be std::cout).

    In other words, when you do

    MyFoo object;
    std::cout << object;
    

    this is "syntactic sugar" for the following function call:

    MyFoo object;
    operator<<(std::cout, object);
    

    and would call a version of operator<< that looked like:

    ostream& operator<<(ostream& out, const MyFoo& my_object);
    

    If the above function was not defined, then you'd get an error like you're currently experiencing.

提交回复
热议问题