trouble with derived class

Currently working on a project which uses a baseclass and a derived class

each class has a header file and an implementation file along with the driver program (5 total files)

the baseclass deals with points x and y

the derived class deals with the points but works off of it obtaining a radius, circumference and area

Currently having a ton of problems with redefinitions and receiving these error codes

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\point.cpp(7): error C2572: 'point::point' : redefinition of default parameter : parameter 2

1> c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\point.h(7) : see declaration of 'point::point'
1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\point.cpp(7): error C2572: 'point::point' : redefinition of default parameter : parameter 1

1> c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\point.h(7) : see declaration of 'point::point'

1> circle.cpp

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(5): error C2572: 'circle::circle' : redefinition of default parameter : parameter 3

1> c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.h(6) : see declaration of 'circle::circle'

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(5): error C2572: 'circle::circle' : redefinition of default parameter : parameter 2

1> c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.h(6) : see declaration of 'circle::circle'

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(5): error C2572: 'circle::circle' : redefinition of default parameter : parameter 1

1> c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.h(6) : see declaration of 'circle::circle'

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(19): error C3867: 'circle::getRadius': function call missing argument list; use '&circle::getRadius' to create a pointer to member

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(19): error C3867: 'circle::getRadius': function call missing argument list; use '&circle::getRadius' to create a pointer to member

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(20): error C3867: 'circle::getCircumference': function call missing argument list; use '&circle::getCircumference' to create a pointer to member

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(20): error C3867: 'circle::getCircumference': function call missing argument list; use '&circle::getCircumference' to create a pointer to member

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(21): error C3867: 'circle::getArea': function call missing argument list; use '&circle::getArea' to create a pointer to member

1>c:\users\michael\documents\visual studio 2010\projects\proj7\proj7\circle.cpp(21): error C3867: 'circle::getArea': function call missing argument list; use '&circle::getArea' to create a pointer to member

point.h (baseclass)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#ifndef POINT_H
#define POINT_H
class point
{
	public:
		point(double init_x = 0.0, double init_y = 0.0);  	// sets x to init_x and y to init_y
									//  or uses the default values
		void setPoint(double init_x, double init_y);		// sets x to init_x and y to init_y
		void print() const;		// prints a point in the form (x, y) with a precision of 1
		double getX() const;		// returns the value of x
		double getY() const;		// returns the value of y
	private:
		double x;
		double y;
};
#endif 


circle.h (derived class)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include "point.h"
class circle: public point
{
	public:
		circle(double init_x = 0.0, double init_y = 0.0, double r = 0.0);
			// uses default parameters to set x to init_x, y to init_y and radius to r
		
		void print() const;
			// prints the following information about a circle:
			// center point, radius, circumference, area with a precision of 1
		void setRadius(double r);
			// sets radius to r
		double getRadius() const;
			// returns radius
		double getCircumference() const;
			// returns circumference (2 * radius * 3.14159)
		double getArea() const;
			// returns area (3.14159 * radius2)
	private:
		double radius;
};


point.cpp (base implement)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include "point.h"
using namespace std;

point::point(double init_x = 0, double init_y = 0)  	// sets x to init_x and y to init_y
									//  or uses the default values
	{

	x = init_x;
	y = init_y;

	}


		void point::setPoint(double init_x, double init_y)		// sets x to init_x and y to init_y
		{

	x = init_x;
	y = init_y;

		}

		void point::print() const		// prints a point in the form (x, y) with a precision of 1
		{
			cout << "Your center point is (" << x << "," << y << ")" << endl; 
		}

		double point::getX() const		// returns the value of x
		{
			
			return x;
		}

		double point::getY() const		// returns the value of y
		{
			
				return y;
		}


circle.cpp (derived implement)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include "circle.h"
using namespace std;

circle::circle(double init_x = 0, double init_y = 0, double r = 0) : point(init_x, init_y)
			// uses default parameters to set x to init_x, y to init_y and radius to r
{

	radius = r; 

}
		void circle::print() const  
			// prints the following information about a circle:
			// center point, radius, circumference, area with a precision of 1
		{
			
		point::print();
		
		cout << "Your radius is " << circle::getRadius << endl;
		cout << "Your circumference is " << circle::getCircumference << endl;
		cout << "Your area is " << circle::getArea << endl;

		}
		void circle::setRadius(double r) 
			// sets radius to r
		{
			radius = r;
		}
		double circle :: getRadius() const
			// returns radius
		{
			return radius;
		}
		double circle::getCircumference() const
			// returns circumference (2 * radius * 3.14159)
		{
			return (2 * radius * 3.14159);
		}
		double circle::getArea() const
		{
			return ((radius * radius) * 3.14159);
		}
			// returns area (3.14159 * radius2 


ayler7.cpp (driver program)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include "circle.h"

using namespace std; 

int main()
{

	circle C1(1,2,3);

	circle C2();

	C1.print();


	
	


	return 0;
}


also cannot use set functions with C2?

help much appreciated, please give all the feedback you can.
Not sure about your class naming, I wouldn't really expect a circle to derive from a "point". Doesn't really matter right now though I suppose.

If your circle class is going to use the x/y from the point class, make them protected not private.

Default parameters, for example point(double init_x = 0.0, double init_y = 0.0); can not be listed in both the definition and the declaration of the function (which is why you are getting all of those "redefinition" errors. Remove the 0.0 from functions like this. point::point(double init_x = 0, double init_y = 0)

double circle :: getRadius() const
Remove spaces on either side of ::

circle.h
1
2
3
public:
	circle():radius(1){};
	circle(double, double, double);


circle.cpp
1
2
3
circle::circle(double init_x, double init_y, double r) : point(init_x, init_y)

{


point.h
1
2
3
public:
	point():x(0),y(0){};
	point(double, double); 


point.cpp
1
2
3
point::point(double init_x, double init_y)

{


Inside circle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
void circle::print() const
// prints the following information about a circle:
// center point, radius, circumference, area with a precision of 1
{

	point::print();

	cout << "Your radius is " << circle::getRadius() << endl;
	cout << "Your circumference is " << circle::getCircumference() << endl;
	cout << "Your area is " << circle::getArea() << endl;

}


thank you both for great feedback, tweaked it with more of a combination of both to the best of my knowledge and have it running perfectly, thanks.
Topic archived. No new replies allowed.