Let's say in a class called 'coordinates', I store two variables x and y. Is there a way I can make another variable in another class of 'coordinate' type so I could then store the vertices (multiple x & y coordinates) of the shape in a list? Would this just be creating objects of coordinate called points and storing them in a list?
You would, but with something so simple as a coordinate class that is doing no more than holding two numbers, it feels unnecessary to make them private.
If the vector is held inside another class, such as octagon:
Allowing for private/public access. If you make lots_of_coordinates private, you'll need a function to pass the coordinates in.
Although a well-formed octagon shouldn't be able to exist without 8 coordinates already inside it, so really the octagon constructor should insist on being given eight coordinates to begin with.
it returns a 'coordinate' object, as written.
you could make one for get x and get y individually if you prefer, returning int or double or whatever x and y are.
but this returns both x and y (eg, (30,40) as 3040.
No it doesn't. It returns an object of type Coordinate. That's all.
What you're describing is simply a problem with the code you've written to display the values of a Coordinate object. Show us that code, and we can see where the problem is.
So when calling cout << get_copy_of_coordinate(0); from the Octagon class, 30 40 of type coordinate is called.
Your language is very muddled and vague here. That's making it harder for us to understand what you're really saying, and I suspect it's making it harder for you to think clearly about what your code is doing and what the problem might be.
A function is called.
A function returns a value. Hence, a value is returned by a function. That value can be an object.
So:
An object of type Point is returned by get_copy_of_coordinate().
"30 40" is what is displayed, when you stream the results to standard output.
If you need to access the values of x and y independently, you can add "getter" methods to your Point class.
However, if the only reason you need to do that is for displaying the values in a nicer format, why not simply rewrite your >> operator to do that?
I'm unsure on how to access the x and y values independently from the octagon class?
Just call those methods on the Point object that is returned by get_copy_of_coordinate() .
I'll need to access x and y independently as I need to pass them though other functions.
You could consider, as an alternative, simply passing the Point object through to those other functions, and having those functions call the getter functions to get the values.
I've tried calling point.getX(get_copy_of_coordinate(0)); with 'point' being the object of Point class but this doesn't work. Could you please clarify on how to call the values independently?