visual studio 2013 - c++ operator<< overloading -


I am starting in C ++ and I have the following problem when I run the following code in VS2013 Receives an error.

  class Y {public: y (int un_x, int un_y): x_ (un_x), y_ (un_y) {} int x () const {return x_; } Int y () const {return y_; } Private: int x_; Int y_; }; Class X {Private: Y coordination; Public: // Some code ... Y position () const {return coordination; } Zero Exhibition (Ostream and Output) Const (output & lt; & Lt; "Object is in position" & lt; & Lt; Post(); }}; Ostream & amp; Operator & lt; & Lt; (Ostream & Output, Y X) {Output & lt; & Lt; "("   

If I create some_object object of class X and try to:

  cout < & Lt; Some_object;   

I get the followng error:

  error C2679: binary '& lt; & lt; & gt; : No operator found which does not take a right hand operation type 'const Y' (or an acceptable conversion)    

what & lt; & Lt; operator defined after that do you try to use it? Is this after the display () function? If so, you need to move it so that it is defined before experiment, or at the very least, declare it (which provides a prototype for it):

  ostream & amp; Operator & lt; & Lt; (Ostream and Output, Y X);   

As a sidenote, you should give example y with constant reference instead of value:

  ostream & amp; Operator & lt; & Lt; (ostream & output, y const & x);    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -