Jump to content
  • Advertisement
Sign in to follow this  
dcuk

working with array and pointers

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

sorry about triple posting, i had really bad probelms with connection kept coming up with server error :s, so unsure whether i was, sincerly sorry. erm the question was supposed to be, im unsure how to change the pointer to point to the next element in array, im not sure how to initiaze it to be more precise, i originally thought you can increment it by pointer++, and so on, but leads me to think my code is wrong somewhere along the line, so thought best place to find out is here :D! I have set up two Item objects in Player class constructor and when the gets into case 3 in Store::Sell ,want it to be able to go one by one through them, i realise i need array which *hopefully* implemented just need to be able to do it?! i tried the mPoint++ but to no avail
void Store::Sell(Player & player, int type) {
	Item * mPoint;
	int select=0;
	string cat="Default";
	if(type == 1) { 
		cat = "Weapon";
		mPoint = player.getWeapon();
	}
	if(type == 2) { 
		cat = "Armour"; 
		mPoint = player.getArmor();
	}
	else if(type == 3) { 
		cat = "Item"; 
		mPoint = player.getItem();
	}
	switch ( type ) {
		case 1: 
			cout <<"\n\t\t" << cat << ": \t\t" << mPoint->GetName() << "\n";
			cout << "\t\tValue is: \t\t" << mPoint->GetValue() << "\n";
			cout << "\t\tDamage Range: \t\t0\n";
			break;
		case 2:
			cout <<"\n\t\t" << cat << ": \t\t" << mPoint->GetName() << "\n";
			cout << "\t\tValue is: \t\t" << mPoint->GetValue() << "\n";
			cout << "\t\tDamage Protection: \t\t0\n";
			break;
		case 3:
			cout <<"\n\t\t" << cat << ": \t\t" << mPoint->GetName() << "\n";
			cout << "\t\tValue is: \t" << mPoint->GetValue() << "\n";
			cout << "\t\tQuantity is: \t" << mPoint->GetQty() << "\n";
			cout << "\t\tDesc: \t\t" << mPoint->GetDesc() << "\n";
			break;
	}





snippet from Player declaration: Item * mItem; ..also the player constructor mItem = new cItem[]; cItem("Potion",5, 10, "Healing Tonic"); cItem("Ether", 3, 40, "Partially restores MagicPoints"); [Edited by - dcuk on September 23, 2005 1:37:15 PM]

Share this post


Link to post
Share on other sites
Advertisement
Careful about that triple posting - I've cleaned it up for you though. [wink]

Now, you might want to actually ask a question. I'm assuming you have a problem with that source code that you'd like some help with? Tell us what the problem is, and what error messages you got, someone might be able to help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!