Problem with References and Pointers

Hello,

I have an error in

Equal(C1, C3); //ERROR

Error C2664 'void Equal(Circle &,Circle &)': cannot convert argument 2 from 'Circle *' to 'Circle &'


How can I fix it?

Thank you

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
using namespace std;

class Point
{
public:
	void input()
	{
		cout << endl;
		cout << "X: ";
		cin >> X;
		cout << "Y: ";
		cin >> Y;
	}
	double X;
	double Y;
};

class Circle
{
	static int count;

private:
	double radius;
	Point center;


public:
	void input()
	{
		cout << endl;
		cout << "Radius: ";
		cin >> radius;
	}
	void DOUBLE()
	{
		radius *= 2;
	}

	Circle() {}
	Circle(Point p)
	{
		center = p;
		count++;
	}


	~Circle()
	{
		count--;
		cout << "Radius is: " << radius << " ";
		cout << "X of Center is: " << center.X << " " << "Y of Center is : " << center.Y << endl;
		cout << "Count is: " << count << endl;
	}
	friend void Equal(Circle &C1, Circle &C2);

};

void Equal(Circle& C1, Circle& C2)
{
	if (C1.radius == C2.radius)
	{
		if ((C1.center.X == C1.center.Y) && (C2.center.X == C2.center.Y))
		{
			cout << "Two Circle is Equal" << endl;
		}
	}
	else
	{
		cout << "Two Circle is NOT Equal" << endl;
	}
}
int Circle::count = 0;

int main()
{
	Point P1;
	P1.input();

	Circle C1(P1);
	C1.input();

	Point P2;
	P2.input();

	Circle C2(P2);
	C2.input();

	C1.DOUBLE();

	Equal(C1, C2);



	Point P3;
	P3.input();

	Circle* C3;
	C3 = new Circle(P3);
	C3->input();

	Equal(C1, C3); //ERROR


	return 0;
}
Last edited on
Equal(C1, *C3); since C3 is a pointer, not a Circle.
There are 2 ways to solve this.

1. Dereference the pointer

Equal(C1, *C3); C3 is a pointer to a Circle object and not actually a Circle

2. Don't use the pointer in the first place. I know you've probably used it to just try them out, but in this instance it's not needed. Especially because you've allocated memory and then never deleted it. This is bad practice. Always make sure you deal with any memory you've allocated.
Topic archived. No new replies allowed.