celere
asked on
can someone please tell me what this does?
I'm taking a beginner's C++ class, and long story, but for now I have to work without the textbook.
This is from a class point (for a triangle) example.
I have a basic understanding of classes, but what I can't find any help on is this:
double distance (const point& another) const;
My questions: what does the ampersand at the end of point& do, and is "another" a keyword, or is it an arbitrary assignment, and what does it do?
Thank You Thank You, for your time.
This is from a class point (for a triangle) example.
I have a basic understanding of classes, but what I can't find any help on is this:
double distance (const point& another) const;
My questions: what does the ampersand at the end of point& do, and is "another" a keyword, or is it an arbitrary assignment, and what does it do?
Thank You Thank You, for your time.
The ampersand means the variable takes a reference, and "another" is a type, not a keyword.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another is not a type or a keyword, it is a variable of type "point".
I'm guessing that
double distance (const point& another) const;
is supposed to be a member function of the class point. If so then good old Pythagoras would help you determine the distance from point to point.
class point
{
double x,y;
public:
point(double _x,double _y);
double distance(const point& another) const
{
double d=...;
// pythagoras
}
};
Regards,
Mike.
I'm guessing that
double distance (const point& another) const;
is supposed to be a member function of the class point. If so then good old Pythagoras would help you determine the distance from point to point.
class point
{
double x,y;
public:
point(double _x,double _y);
double distance(const point& another) const
{
double d=...;
// pythagoras
}
};
Regards,
Mike.
Correction: Another is not a type or a keyword, it is a reference to a variable of type "point".