inputting numbers within a class
Apr 3, 2014 at 3:09pm UTC
I was wondering how to input an object's values for a Cartesian class. Would this involve overloading the input function, or would it be something else?
Apr 3, 2014 at 3:14pm UTC
Really depends on what you want to do.
If you want to do something like this:
1 2
Cartesian coord;
cin >> coord;
Then yes, that would involve overloading the >> operator.
There are other approaches, such as prompting the user for x and y, possibly editing the values, then calling a setter in the Cartesian class.
Apr 4, 2014 at 5:06pm UTC
Would I put that segment of code in the main function then? and overload the >> operator within the Cartesian class?
Apr 4, 2014 at 5:37pm UTC
Would I put that segment of code in the main function then?
That depends on where in your code you want to read in the coordinates, but yes, you can do that in main.
overload the >> operator within the Cartesian class?
Yes.
Topic archived. No new replies allowed.