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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a qestion about functions (2 sets of parameters)

Status
Not open for further replies.

lordhuh

Programmer
Apr 25, 2000
96
US
i know in a class u can do this
Code:
class clsAttack
{public:
	void attack(clsPlayer* player, clsMonster* monster)
	{

	}
	void attack(clsMonster* monster, clsPlayer* player);
	{

	}
}
it will do 2 different things based on what parameters you pass it. how can i do that outside of a class. do i just make both functions? please help Karl Pietri
 
Yep, if they are both funcitons outside of a class it will still behave the same. Function Overloading may be done anywhere.

Ex:

//function Prototypes
void attack(clsPlayer*, clsMonster*);
void attack(clsMonster*, clsPlayer* );

int main()
{
...
}

void attack(clsPlayer* pPlayer, clsMonster* pMonster)
{
...
}

void attack(clsMonster* pMoster, clsPlayer* pPlayer)
{
...
}

Cheers
Matt



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top