I am trying to work out coordinates in a base class using a member function. Whilst I know I have the correct formula, I keep getting the following output if I comment out lines 78 relating to calls for the circle class and member functions
[output]
The coordinates are (10,10)
The coordinates are (1,1)
The distance between 2 points is 0
[\output]th
Furthermore, when I start to make the circle calls after I remove the omments I receive the following errors
"
C:\Users\shish\Desktop\C++ programmes\Exercise11.6_5\main.cpp||In function 'int main()':|
C:\Users\shish\Desktop\C++ programmes\Exercise11.6_5\main.cpp|82|error: assignment of function 'Circle Circle1()'|
C:\Users\shish\Desktop\C++ programmes\Exercise11.6_5\main.cpp|82|error: cannot convert 'Point' to 'Circle()' in assignment|
C:\Users\shish\Desktop\C++ programmes\Exercise11.6_5\main.cpp|82|error: cannot convert 'Point' to 'Circle()' in assignment|"
So this: cout << "The center of the circle is " << "(" << Point().x << "," << Point().y << ")"<< endl;
makes no sense. You're trying to create a Point object right there, and get its x variable, and create a Point object right there, and get its y variable.
I suspect you meant: cout << "The center of the circle is " << "(" << x << "," << y << ")"<< endl;
Circle class has a member variable x, and member variable y. You can just use them in any circle object.
Circle1 = Point1; If you want to do this, you're going to have top write code explaining to the compiler what you want it to do when you try to assign a Point to a Circle.
Circle Circle1();
This says "there exists a function, named Circle1, that takes no parameters and returns an object of type Circle". Perhaps you meant to create a Circle object using the Circle object's constructor, Circle(Point(double x, double y), double r = 1.0) ? That is the only way to create a Circle, since it has only that one constuctor. Although that constructor doesn't make much sense either... what are you trying to do with that constructor?
Thanks very much! I have since amended it all and come up with the following. I believe I will have to create an = operator in the circle class in order to assign a point object to a circle object.