I write 3 constructor class and splits into c.h c.cpp but I have got extra definition in my cpp program. My destructor show error
My program *.h and *.cpp are
#include "c2.h"
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
usingnamespace std;
//*************************************************
int main()
//*************************************************
{
double xc, xpoint, radius;
double yc, ypoint;
// get x & y axis
cout << "This program will calculate whether the specific point is inside the circle ";
cout << "\nWhat is the radius of the circle ";
cin >> radius;
cout << "\nWhat is x - axis of the interest point? ";
cin >> xpoint;
//40
cout << "\nWhat is y - axis of the interest point? ";
cin >> ypoint;
cout << "\n";
circle c(xpoint, ypoint);
Your question doesn't make any sense. You haven't shown us line 44 of your code, so how can we tell what might be wrong with it?
You're trying to delete the circle object within its own destructor. That makes no sense. The destructor is what gets called automatically when the object it deleted, so what you've written would lead to infinite recursion.
Your class Circle has no constrcutor with two parameters. So the compiler issues the error in your line 44.
Also there is no any sense in the constructor
1 2
circle(double x, double y , double radius)
{ x=0; y=0; r = radius; }
Another tip would be to use initializer lists which give you more functionality for your constructor, like for example you can initialize const variables with a initializer list but not with your constructors.
If you are using the initializer lists you don't need to for simple things like what you have. Here I will go through one of them really quick so you know what everything does.
circle() : x(0), y(0) {}
basically it works exactly like the code you have. Meaning x(0) assigns 0 to the member X when you use that constuctor, and y(0) assigns 0 to the member y.
For this one circle(double radius) : x(0), y(0), r(radius) {}
It is doing the exact same thing for x and y. But it is assigning whatever you pass as the argument radius to the member variable r. So if I called the constructor like this circle one(5); it would assign the number 5 to radius.
Also notice that we have the blank {} after each constructor that is telling the compiler we have already defined the constructor. So we wouldn't need these circle::circle(){ x=-0; y=0; }
Oh and another thing to note is you can do expressions in the list also like circle(double radius) : x(0), y(0), r(radius * 2) {}
Set all the members to appropriate values in every constructor.
Write an additional two argument constructor (or use default values) if you find it handy.
The problem is not in trivially constructibility and so on. The problem is that the constructor has no any sense because its first two parameters are not used.:)
And I pointed out this three times.:) This is the forth time.:)
> Since double's are trivial there must be a easy way to initialize the const double member ;p
An object of type constdouble is not trivially constructible.
> It's still a good habit for somebody learning C++ to get into.
That is a matter of opinion. IMNSHO, it is a good idea not to use member initializers for members that are trivially constructible and trivially copyable, and thereby evade the nasty 'order-of-initialization problem'.
> "Ludicrous" is unnecessarily rude.
Be that as it may, the "should be" in that post remains unquestionably ludicrous.
Could you say what you wanted to say pointing this reference?
I think the reference speaks for itself. You instructed the OP to change the structure of his code and this link provides some background and justification for your suggestion.
@booradley60
I think the reference speaks for itself. You instructed the OP to change the structure of his code and this link provides some background and justification for your suggestion.