I try to run the following, but I keep getting the error "error C2664: 'Card::SetName' : cannot convert parameter 1 from 'const char [23]' to 'char'"

I also got the following error;
error C2664: 'Beginning' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'

I'm not that familiar with Classes, Objects, and char/string, so I would like some help please

#include <stdlib.h>
#include <windows.h>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

//srand(time(0));

vector<string> KaibaHand;
vector<string>::iterator it;

//string KaibaDeckArray[] = {"BLUE EYES WHITE DRAGON", "BLUE EYES WHITE DRAGON", "BLUE EYES WHITE DRAGON", "VORSE RAIDER", "BLADE KNIGHT",
//						"KAISER SEA HORSE", "LORD OF DRAGONS", "THUNDER DRAGON", "THUNDER DRAGON", "THUNDER DRAGON", 
//						"CYBER JAR", "SPEAR DRAGON", "TWIN HEADED BEHEMOTH", "X CANNON HEAD", "Y DRAGON HEAD",
//						"Z HEAD TANK", "VAMPIRE LORD", "SPIRIT RYU", "POSSESSED DARK SOUL", "LA JINN THE MYSTICAL GENIE OF THE LAMP",
//						"DIFFERENT DIMENSION DRAGON", "GIANT GERM", "GIANT GERM", "GIANT GERM", "SHRINK", 
//						"HEAVY STORM", "MONSTER REBORN", "POLYMERIZATION", "POT OF GREED", "FLUTE OF SUMMONING DRAGON",
//						"COST DOWN", "ENEMY CONTROLLER", "SILENT DOOM", "SOUL EXCHANGE", "FIEND'S SANCTUARY",
//						"VIRUS CANNON", "RING OF DESTRUCTION", "DRAGON'S RAGE", "CRUSH CARD", "INTERDIMENSIONAL MATTER TRANSPORTER"};


//vector<string> KaibaDeck(KaibaDeckArray, KaibaDeckArray + sizeof(KaibaDeckArray)/sizeof(*KaibaDeckArray));
//vector<string>::iterator dt;

vector< vector<string> > Field(2, vector<string>(5));

vector<string> KaibaGraveyard;
vector<string>::iterator gt;


void Beginning(vector<string> &KaibaHand, vector<string> &KaibaDeck);
void DrawForKaiba(vector<string> &KaibaHand, vector<string> &KaibaDeck);
void MainPhase(vector<string> &KaibaHand,  vector<string> &KaibaGraveyard);
void BattlePhase(vector< vector<string> > &Field);

void FieldFunction(vector< vector<string> > &Field);
void KaibaHandFunction(vector<string> &KaibaHand);

int KaibaMainHand;
int CardSlot;
int Decision;
int KaibaDeckSize;
int DrawChoice;
int MonsterCard;

class Card
{
public:
	int GetAttack() {return Attack;}
	int GetDefense() {return Defense;}
	string GetName() {return Name;}
	void SetAttack(int setAttack) { Attack = setAttack; }
	void SetDefense(int setDefense) { Defense = setDefense; }
	string SetName(char setName) {Name = setName; }

private:
	int Attack;
	int Defense;
	string Name;
};



int main()
{
	srand(time(0));
	//Card KaibaDeck[40];
	vector<Card> KaibaDeck(40);
	
	
	KaibaDeck[0].SetAttack(3000), KaibaDeck[1].SetAttack(3000), KaibaDeck[2].SetAttack(3000), KaibaDeck[3].SetAttack(1900), KaibaDeck[4].SetAttack(1600),
	KaibaDeck[5].SetAttack(1700), KaibaDeck[6].SetAttack(1300), KaibaDeck[7].SetAttack(1600), KaibaDeck[8].SetAttack(1600), KaibaDeck[9].SetAttack(1600),
	KaibaDeck[10].SetAttack(900), KaibaDeck[11].SetAttack(1900), KaibaDeck[12].SetAttack(1500), KaibaDeck[13].SetAttack(1800), KaibaDeck[14].SetAttack(1500),
	KaibaDeck[15].SetAttack(1500), KaibaDeck[16].SetAttack(2000), KaibaDeck[17].SetAttack(1000), KaibaDeck[18].SetAttack(1200), KaibaDeck[19].SetAttack(1800),
	KaibaDeck[20].SetAttack(1500), KaibaDeck[21].SetAttack(1000), KaibaDeck[22].SetAttack(1000), KaibaDeck[23].SetAttack(1000);

	KaibaDeck[0].SetDefense(2500), KaibaDeck[1].SetDefense(2500), KaibaDeck[2].SetDefense(2500), KaibaDeck[3].SetDefense(1200), KaibaDeck[4].SetDefense(1000),
	KaibaDeck[5].SetDefense(1000), KaibaDeck[6].SetDefense(1200), KaibaDeck[7].SetDefense(1500), KaibaDeck[8].SetDefense(1500), KaibaDeck[9].SetDefense(1500),
	KaibaDeck[10].SetDefense(800), KaibaDeck[11].SetDefense(0), KaibaDeck[12].SetDefense(800), KaibaDeck[13].SetDefense(600), KaibaDeck[14].SetDefense(1600),
	KaibaDeck[15].SetDefense(1300), KaibaDeck[16].SetDefense(1200), KaibaDeck[17].SetDefense(1000), KaibaDeck[18].SetDefense(800), KaibaDeck[19].SetDefense(500),
	KaibaDeck[20].SetDefense(1600), KaibaDeck[21].SetDefense(100), KaibaDeck[22].SetDefense(100), KaibaDeck[23].SetDefense(100);

	KaibaDeck[0].SetName("BLUE EYES WHITE DRAGON"), KaibaDeck[1].SetName("BLUE EYES WHITE DRAGON"), KaibaDeck[2].SetName("BLUE EYES WHITE DRAGON"), KaibaDeck[3].SetName("VORSE RAIDER"), KaibaDeck[4].SetName("BLADE KNIGHT"),
	KaibaDeck[5].SetName("KAISER SEA HORSE"), KaibaDeck[6].SetName("LORD OF DRAGONS"), KaibaDeck[7].SetName("THUNDER DRAGON"), KaibaDeck[8].SetName("THUNDER DRAGON"), KaibaDeck[9].SetName("THUNDER DRAGON"), 
	KaibaDeck[10].SetName("CYBER JAR"), KaibaDeck[11].SetName("SPEAR DRAGON"), KaibaDeck[12].SetName("TWIN HEADED BEHEMOTH"), KaibaDeck[13].SetName("X CANNON HEAD"), KaibaDeck[14].SetName("Y DRAGON HEAD"),
	KaibaDeck[15].SetName("Z HEAD TANK"), KaibaDeck[16].SetName("VAMPIRE LORD"), KaibaDeck[17].SetName("SPIRIT RYU"), KaibaDeck[18].SetName("POSSESSED DARK SOUL"), KaibaDeck[19].SetName("LA JINN THE MYSTICAL GENIE OF THE LAMP"),
	KaibaDeck[20].SetName("DIFFERENT DIMENSION DRAGON"), KaibaDeck[21].SetName("GIANT GERM"), KaibaDeck[22].SetName("GIANT GERM"), KaibaDeck[23].SetName("GIANT GERM"), KaibaDeck[24].SetName("SHRINK"), 
	KaibaDeck[25].SetName("HEAVY STORM"), KaibaDeck[26].SetName("MONSTER REBORN"), KaibaDeck[27].SetName("POLYMERIZATION"), KaibaDeck[28].SetName("POT OF GREED"), KaibaDeck[29].SetName("FLUTE OF SUMMONING DRAGON"),
	KaibaDeck[30].SetName("COST DOWN"), KaibaDeck[31].SetName("ENEMY CONTROLLER"), KaibaDeck[32].SetName("SILENT DOOM"), KaibaDeck[33].SetName("SOUL EXCHANGE"), KaibaDeck[34].SetName("FIEND'S SANCTUARY"),
	KaibaDeck[35].SetName("VIRUS CANNON"), KaibaDeck[36].SetName("RING OF DESTRUCTION"), KaibaDeck[37].SetName("DRAGON'S RAGE"), KaibaDeck[38].SetName("CRUSH CARD"), KaibaDeck[39].SetName("INTERDIMENSIONAL MATTER TRANSPORTER");


	Beginning(KaibaHand, KaibaDeck);


	while (KaibaDeckSize>0)
		{
			KaibaDeckSize = KaibaDeck.size();
			if (KaibaDeckSize==0)
			{
				cout<<"There are no cards left. You have DECKED OUT"<<endl;
				break;
			}
			cout<<endl<<"DRAW PHASE (Press 1 to draw, 0 to CONCEDE)"<<endl;
			cin>>DrawChoice;
			if (DrawChoice==0)
			{
				break;
			}
			
			else
			{
			DrawForKaiba(KaibaHand, KaibaDeck);

			cout<<endl<<"MAIN PHASE"<<endl;
			MainPhase(KaibaHand, KaibaGraveyard);
			cout<<endl<<"BATTLE PHASE"<<endl;
			BattlePhase(Field);
			cout<<endl<<"END OF TURN"<<"\n"<<endl;
			}
		}


cout<< "\n"<<"GAME OVER"<<endl;

return 0;
} 



void Beginning(vector<string> &KaibaHand, vector<string> &KaibaDeck)
{
	cout<<"DRAW YOUR FIRST 5 CARDS"<<endl;
	for (int i=1; i<6; i++)
		{
			cout<<"(Press 1 to draw)"<<endl;
			cin>>DrawChoice;
			if (DrawChoice==0)
			{
				break;
			}
			
			else
			{
			DrawForKaiba(KaibaHand, KaibaDeck);
			}
		}
}


void DrawForKaiba(vector<string> &KaibaHand, vector<string> &KaibaDeck)
{
KaibaDeckSize = KaibaDeck.size();
cout<<"BEFORE you draw, there were "<<KaibaDeckSize<<" cards left in the Deck"<<endl;
int DrawKaiba = rand() % KaibaDeckSize + 1;
cout<<"Random number is: "<<DrawKaiba<<" "<<endl;

cout<<"You drew "<<KaibaDeck[DrawKaiba-1].GetName()<<endl;
KaibaHand.push_back(KaibaDeck[DrawKaiba-1]);
KaibaDeck.erase (KaibaDeck.begin()+DrawKaiba-1);


}//DrawforKaiba




void KaibaMainPhase(vector<string> &KaibaHand, vector<string> &KaibaGraveyard)
{
	while(1)//so the while loop NEVER breaks unless you have a 'break' later on
	{
	cout<<"Would you like to continue the Main Phase? (Yes-'1'  No-'0')"<<endl;
	cin>>Decision;
		if (Decision==0)
		{
			break;
		}

		KaibaHandFunction(KaibaHand);
		cout<<"\n";
		FieldFunction(Field);

		cout<<"Which card in your hand do you wish to play? (if none, press '0', to check Graveyard press '-1')"<<endl;
		cin>>KaibaMainHand;
		if (KaibaMainHand==-1)
		{
			cout<<"Your graveyard contains: "<<endl;
			for (gt=KaibaGraveyard.begin(); gt<KaibaGraveyard.end(); gt++)
			{
				cout<<"    "<<*gt<<endl;
			}
		}
		else if (KaibaMainHand>0)
		{
			cout<<"Where do you want to place this card?"<<endl<<" (1-5 for Monster zones, 6-10 for M/T, 11 for Graveyard)"<<endl;
			cin>>CardSlot;
			
			for (int j=1; j<6; j++)
			{
					if (CardSlot==j)
					{
					cout<<"The card is played in slot "<<j<<" of the 1st row"<<endl;
					Field[0][j-1]=KaibaHand[KaibaMainHand-1];
					KaibaHand.erase (KaibaHand.begin()+KaibaMainHand-1); //Card moves from Hand to field
					break;
					}
			}

			for (int j=6; j<11; j++)
			{
					if (CardSlot==j)
					{
					cout<<"The card is played in slot "<<j-5<<" of the 2nd row"<<endl;
					Field[1][j-6]=KaibaHand[KaibaMainHand-1];
					KaibaHand.erase (KaibaHand.begin()+KaibaMainHand-1); //Card moves from Hand to field
					break;
					}
			}
			if (CardSlot==11)
			{
				cout<<KaibaHand[KaibaMainHand-1]<<" is discarded to the Graveyard"<<endl;
				KaibaGraveyard.push_back(KaibaHand[KaibaMainHand-1]);
				KaibaHand.erase (KaibaHand.begin()+KaibaMainHand-1); //Discarded card is now erased from Hand			
			}
			
			cout<<"\n";
			FieldFunction(Field);


		}// end of if Mainhand>0


    }// end of while(1)

}



void BattlePhase(vector< vector<string> > &Field)
{
	while(1)//so the while loop NEVER breaks unless you have a 'break' later on
	{
	cout<<"Would you like to continue the Battle Phase? (Yes-'1'  No-'0')"<<endl;
	cin>>Decision;
		if (Decision==0)
		{
			break;
		}

	FieldFunction(Field);
	cout<<"\n";
	cout<<"Which Monster card on your field do you wish to attack with?"<<endl;
	cout<<"(Press 1 for monster in 1st slot, etc. If none, press '0')"<<endl;
	cin>>MonsterCard;
	cout<<"The ATK of "<<Field[0][MonsterCard-1]<<" is "<<Field[0][MonsterCard-1].GetAttack()<<endl;
	cout<<"My "<<Field[0][MonsterCard-1]<<" ATTACKS! "<<endl;
    }// end of while(1)

}

void FieldFunction(vector< vector<string> > &Field)
{
			cout<<endl<<"Your Monster Field contains: "<<endl;
			for (int i=0; i<5; i++)
			{
			cout<<i+1<<". "<<Field[0][i]<<"\t";
			}
	
			cout<<endl<<endl<<"Your M/T Field contains: "<<endl;
			for (int i=0; i<5; i++)
			{
			cout<<i+6<<". "<<Field[1][i]<<"\t";
			}
			cout<<endl<<endl;
}


void KaibaHandFunction(vector<string> &KaibaHand)
{
		cout<<endl<<"Your hand contains: "<<endl;
		for (it=KaibaHand.begin(); it<KaibaHand.end(); it++)
		{
			cout<<*it<<endl;
		}
}

You can't do this: string SetName(char setName) {Name = setName; } You're trying to set a std::string equal to a char , which you can't do. You should try: string SetName(const string& setName) {Name = setName; }

Member Avatar for MonsieurPointer

Also, the second parameter in your prototype

void Beginning(vector<string> &KaibaHand, vector<string> &KaibaDeck);

requires a reference to a vector of strings, but here

Beginning(KaibaHand, KaibaDeck);

KaibaDeck is defined as

vector<Card> KaibaDeck(40);

a vector of Cards.

Thanks for the help. I made the changes but now I'm getting these errors

error C2039: 'GetName' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'

for

void DrawForKaiba(vector<string> &KaibaHand, vector<string> &KaibaDeck)
{
KaibaDeckSize = KaibaDeck.size();
cout<<"BEFORE you draw, there were "<<KaibaDeckSize<<" cards left in the Deck"<<endl;
int DrawKaiba = rand() % KaibaDeckSize + 1;
cout<<"Random number is: "<<DrawKaiba<<" "<<endl;

cout<<"You drew "<<KaibaDeck[DrawKaiba-1].GetName()<<endl;
KaibaHand.push_back(KaibaDeck[DrawKaiba-1]);
KaibaDeck.erase (KaibaDeck.begin()+DrawKaiba-1);


}//DrawforKaiba

and
error C2039: 'GetAttack' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'

for

FieldFunction(Field);
	cout<<"\n";
	cout<<"Which Monster card on your field do you wish to attack with?"<<endl;
	cout<<"(Press 1 for monster in 1st slot, etc. If none, press '0')"<<endl;
	cin>>MonsterCard;
	cout<<"The ATK of "<<Field[0][MonsterCard-1]<<" is "<<Field[0][MonsterCard-1].GetAttack()<<endl;
Member Avatar for MonsieurPointer

Again, you are calling DrawForKaiba with the wrong parameters. In your prototype you defined vector<string>, but you are calling it with vector<Card>; and since the string class doesn't have a method GetName, you get the error. Go over your code and ensure that the parameters you pass to your functions match those as defined in your prototypes!

ok I changed the vectors from type 'string' to 'Card'

But now I'm getting this error message
" error C2679: binary '[' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator<_Myvec>' (or there is no acceptable conversion "


for

if (KaibaMainHand==-1)
		{
			cout<<"Your graveyard contains: "<<endl;
			for (gt=KaibaGraveyard.begin(); gt<KaibaGraveyard.end(); gt++)
			{
				cout<<"    "<<KaibaGraveyard[gt].GetName()<<endl;
			}
		}

and
" binary '[' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator<_Myvec>' (or there is no acceptable conversion) "


for

void KaibaHandFunction(vector<Card> &KaibaHand)
{
		cout<<endl<<"Your hand contains: "<<endl;
		for (it=KaibaHand.begin(); it<KaibaHand.end(); it++)
		{
			cout<<KaibaHand[it].GetName()<<endl;
		}
}
Member Avatar for MonsieurPointer

gt and it are not integers, they are iterators. Google on how to iterate through vectors.

You're using iterators incorrectly. You want to do something like gt->GetName() inside the loop, in the first example.

I just tried gt->GetName(). It works now! thanks

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.