Appretiate some coursework help related to classes.

All im trying to do is compare the elements of two objects

if(asteroid1.getxx == asteroid2.getxx && asteroid1.getyy == asteroid2.getyy)
	{
		cout<<endl;
		cout<<"Collision"<<endl;
	}

All i want to be able to do, is to compare the x and y co-ordinates of my two objects. The intelisense is working and there doesnt seem to by anything wrong other then just lack of knowledge.

so.....what stupid mistake am i making?

Also...second question to field, if i was to move this and just make a comparason function, could i send the object and its elements to another cpp?
*Clarify* passing the co-ordinates of both objects to a function, in the cpp with all my class details.

Help appretiated and thank you!

Are these getxx and getyy member variables or perhaps functions? If the latter, then you need

if(asteroid1.getxx() == asteroid2.getxx() && asteroid1.getyy() == asteroid2.getyy())
	{
		cout<<endl;
		cout<<"Collision"<<endl;
	}

>> if i was to move this and just make a comparason function, could i send the object and its elements to another cpp?
*Clarify* passing the co-ordinates of both objects to a function, in the cpp with all my class details.

Most probably yes, as far as I understood the question.

They are Private member variables. Header code included:

#pragma once
class coord
{
private:
	int xx;
	int yy;
	int velocity;
	int energy;
	//Methods
public:
	//Constructors
	coord(int xxIn, int yyIn, int velocityIn, int energyIn);
	coord(void);
	//Getters
	int getxx(void);
	int getyy(void);
	int getvelocity(void);
	int getenergy(void);
	//Setters
	void updatex(int xxIn);
	void updatey(int yyIn);
	void setvelocity(int velocityIn);
	void setenergy(int energyIn);
	void energycomp();

Are these getxx and getyy member variables or perhaps functions? If the latter, then you need

if(asteroid1.getxx() == asteroid2.getxx() && asteroid1.getyy() == asteroid2.getyy())
	{
		cout<<endl;
		cout<<"Collision"<<endl;
	}

>> if i was to move this and just make a comparason function, could i send the object and its elements to another cpp?
*Clarify* passing the co-ordinates of both objects to a function, in the cpp with all my class details.

Most probably yes, as far as I understood the question.

class coord
{
private:
	int xx;
	int yy;
public:
	int getxx(void);  
	int getyy(void);

Hmm, xx and yy are private member variables, whereas getxx() and getyy() are not. So you have to use these public getters that are there, so you ...

if(asteroid1.getxx( ) == asteroid2.getxx( ) && asteroid1.getyy( ) == asteroid2.getyy( ))
// ..

:)

commented: Fantastic Help..Thank you! +1

Apsalutely fantastic....i cannot thank you enough! I knew it was somthing as simple as that!


class coord
{
private:
	int xx;
	int yy;
public:
	int getxx(void);  
	int getyy(void);

Hmm, xx and yy are private member variables, whereas getxx() and getyy() are not. So you have to use these public getters that are there, so you ...

if(asteroid1.getxx( ) == asteroid2.getxx( ) && asteroid1.getyy( ) == asteroid2.getyy( ))
// ..

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.