'defining object' redeclared as different kind of symbol

Hello all I am currently having problems with defining an array of objects. I am getting 'redeclared as different kind of symbol' error message. The code is below

Would very much appreciate the help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//MissionPlan.cpp
#include <iostream>
#include <string>
#include "MissionPlan.h"
#include "PointTwoD.h"

using namespace std;

//MissionPlan class implementation
MissionPlan::MissionPlan()
{
  //...
}

MissionPlan::~MissionPlan()
{
}

PointTwoD system[50]; //This is where the error occurs

void MissionPlan::DisplayMenu()
{
 //....
}


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
//PointTwoD.cpp
#include <iostream>
#include <string>
#include <math.h>
#include "PointTwoD.h"

using namespace std;

//PointTwoD constructor
PointTwoD::PointTwoD()
{
	int x = 0;
	int y = 0;
	float civIndex = 0;
	float distance = 0;
}

PointTwoD::~PointTwoD()
{
}

float PointTwoD::calDistance(int x, int y)
{
	float result = sqrt((x * x) + (y * y));
	return result;
}

void PointTwoD::setPoint2D(int a, int b)
{
	PointTwoD::x = a;
	PointTwoD::y = b;
}

void PointTwoD::setCivIndex()
{
//...
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//PointTwoD.h
#include "LocationData.h"

class PointTwoD
{
	private:
		float distance;
	public:
		PointTwoD();
		~PointTwoD();
		void setPoint2D(int,int);
		float civIndex;
		int x,y;
		float calDistance(int, int);
		float getDistance();
		void setCivIndex();
		LocationData locationData;
};
The problem is in your constructor. Try this:

1
2
3
4
5
6
7
8
PointTwoD::PointTwoD()
{
	x = 0;
	y = 0;
	civIndex = 0.0;
	distance = 0.0;
}


EDIT:

A couple of more things:

I would change x and y to float.

Line 24 in Point2D.cpp, at the moment what it does is essentially this: ((x*x)+(y*y)) * ((x*x)+(y*y)). Is it what you want to do? Just wondering.
Last edited on
Thanks for the input MarciusV. I did what you suggested but I am still getting the same error.

as for calDistance, no. I am trying to calculate straight line distance between two 2D coordinates with (0,0) as the start point.
Ah, since you intend to use floats, your class functions should take parameters as floats too. Try it and let us know if that fixes it.
@MarciusV
What is wrong with line 24? It looks perfectly fine to me - read it again, it says sqrt not sqr!

As for the error, do you have any other .cpp files? Could we see them? It is possible that you have declared another global variable called system. At the very least, for that, declaring it as static PointTwoD system[50];.
What is wrong with line 24? It looks perfectly fine to me - read it again, it says sqrt not sqr!


Oops, my bad.
Oh wow, changing the name "system" actually fixed the problem. I looked through my code to see if there was any other declaration or definition of "system" but i found none.
I think the word "system" is reserved?

Thanks @NT3 and @MarciusV for the inputs!
Welcome to the world of using namespace std;.
Your compiler probably got tripped up because it thinks you're trying to redeclare the std::system function as something else.

See, just another reason not to use using namespace std;...

EDIT: Just tested it myself, and unfortunately, for my compiler at least, system seems to be declared in the global namespace as well (it's probably #include -ing <stdlib.h> somewhere along the line), so if that's the case for you as well, then you'll probably just have to pick a different name....
Last edited on
Topic archived. No new replies allowed.