Hello everyone,

I am C++ beginner and I have a basic questions regarding classes

Referring to the code below, I am trying to access x and y from the coordinate class in method abc after having run the place method.

I hope this is clear

Here is my code:

class coordinate
{

friend class closedcurve;

public:
    coordinate() {}
    coordinate(double xin,double yin) {x=xin;y=yin;}
    double x;
    double y;
    double getx() { return x; }
    double gety() { return y; }
    friend void place(double a);

};

class circle
{
public: 
    circle(double a);
    ~circle();
    double area();
    double circumference();
    coordinate place(double a);
};

coordinate square::place(double a)
{
... some code

return coordinate(xa,xb);
}

void square::abc(double b)
{

place(b);

how do i access x and y from the coordinate class in here??

}
coordinate blah = place(b);
double x = blah.getx();
double y = blah.gety();

I hope this is what you need. Also, make member variables x and y of class coordinate private or protected.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.