c++ - How to implement the extraction operator in a class? -


i have class reads parts of binary file variables of different types.

class foo { public:     size_t getsizet();     float getfloat();     std::string getstring(); private:     std::ifstream stream; }; 

now i'd implement stream extraction operator described in answer.

class foo { public:     foo &operator>>(foo &foo, size_t &value);     foo &operator>>(foo &foo, float &value);     foo &operator>>(foo &foo, std::string &value); private:     std::ifstream stream; }; 

the code fails compile error message: error c2804: binary 'operator >>' has many parameters. how override stream extraction operator? should distinguish between types , chainable.

as free function, operator signature should be:

foo& operator >>(foo& foo, size_t& value); 

as member function (your case), should be:

foo& operator >>(size_t& value); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -