Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

functions

Status
Not open for further replies.

SotonStu

Programmer
May 7, 2003
33
GB
if i have two objects,in this case cards, each storing a short value that can be accessed by a getvalue() method and i want to apply an int beat(cards c) function to them to see which has a higher value, how do i access the card i want to compare the parameter against. eg:

cards c1 = deck[15]; //Getting a card from an array of consturcted cards
cards c2 = deck[38];
if(c1.beats(c2)) cout << &quot;BEATS&quot;;

I know how i can get at c2 but don't know how i can get the value of c1.

Thanks again
 
Since the beats() function is a member function of the class it will have access to the member variables of the c1 object (instance).
Code:
class cards{
public:
  int value;
  bool beats( const cards& otherCard){
    return value > otherCard.value;
  }
.... rest of class
}


-pete
[sub]I just can't seem to get back my IntelliSense[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top