Memberwise assignment cartesian class c++ -


i have code cartesian class , want add memberwise assignment set values of coord1 coord2. not quite sure how go doing this. syntax writing memberwise assignment class objects? make changes class itself, or put them in main function?

#include <iostream> using namespace std;  class cartesian { private:     double x;     double y;  public:     cartesian( double = 0, double b = 0) : x(a), y(b){}      friend istream& operator>>(istream&, cartesian&);     friend ostream& operator<<(ostream&, const cartesian&); };  istream& operator>>(istream& in, cartesian& num) {     cin >> num.x >> num.y;     return in; }  ostream& operator<<( ostream& out, const cartesian& num) {     cout << "(" << num.x << ", " << num.y << ")" << endl;     return out; }  int main() { cartesian   coord1, coord2;      cout << "please enter first coordinates in form x y" << endl;     cin >> coord1;      cout << "please enter second coordinates in form x y" << endl;     cin >> coord2;      cout << coord1;     cout << coord2;      return 0; } 

do simple way: make members public, using struct , leaving out access specifiers. data hiding not make sense if provide full access anyway.

also, can leave out custom constructors, can assign members @ once without.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -