0

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!

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Suicidal_tool
Featured Replies
  • 1

    [code] class coord { private: int xx; int yy; public: int [COLOR="Green"]getxx[/COLOR](void); int [COLOR="Green"]getyy[/COLOR](void); [/code] Hmm, [ICODE]xx[/ICODE] and [ICODE]yy[/ICODE] are private member variables, whereas [ICODE]getxx()[/ICODE] and [ICODE]getyy()[/ICODE] are not. So you have to use these public getters that are there, so you ... [code] if(asteroid1.getxx( ) == asteroid2.getxx( ) && … Read More

0

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.

0

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.

1
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( ))
// ..

:)

Comments
Fantastic Help..Thank you!
0

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( ))
// ..

:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.