Overloaded with the assignment operator: Why can this program compile it on G ++?

xiaoxiao2021-04-03  232

// Generally, GCC is the best compiler for learning C / C . However, the program can be compiled in G 3.4.4.

#include #include using namespace std;

Class Val_box {private: int val;} void set (int new_val) {val = new_val;} Val_box & operator = (Val_box & right) // In fact, const is required {// Reserved Operator's Heavy Duty Val = Right.val; Return * this;}};

class query {private: vector val_box_collection; public: void Insert (int val) {val_box temp_val_box; temp_val_box.set (val); val_box_collection.push_back (temp_val_box);} friend ostream & operator << (ostream & os, query & right) {For (Vector :: item = right.val_box_collection.begin (); it! = Right.val_box_collection.end (); iTer) {OS << (* iter) .get () << " / t ";} return os;}};

INT main () {query test_class; test_class.insert (1); test_class.insert (2); test_class.insert (3); cout << Test_class << endl; cin.get (); return 0;}

/ * VC2005 error description: Error 1 Error C2679: binary '=': No Operator Found Which Takes a Right-Hand OPERANDEPE 'Const Val_box' (or there is no acceptable conversion)

转载请注明原文地址:https://www.9cbs.com/read-131642.html

New Post(0)