Unrecognized operand error

Hi, I'm currently writing a program for my C++ class, and there's one error message that keeps popping up everytime I compile that I can't understand.

It says:

1
2
3
 137: error: could not convert 'numCreatures' from 'Creatures*' to 'std:: {aka std::basic_string<char>'

  error: no match for 'operator[]' (operand types are 'Creatures' and 'int')


It's only popping up for these once section of code, and I can't figure out why. Here's the two sections respectively:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int deleteCreatures(Creatures numCreatures[], int curNumCreatures)
{
	bool found;
	
	string temp;
	
	"The following is a list of all the creatures you take care of: \n";
	for(int i = 0; i < curNumCreatures; i++)
	{
		cout << numCreatures[i].name << endl;
	}
	
	cout << endl << "What creature do you wish to remove?\n";
	cout << "CREATURE NAME: ";
	getline(cin, temp);
	
	found = moveArrayElements(numCreatures, curNumCreatures, temp);
	
	if(found == true)
	{
		cout << "You have removed " << temp;
	
		curNumCreatures--;
	}
	else
	{
		cout << "Invalid. Please enter a saved creature name.\n";
		getline(cin, temp);
	}
	
	return curNumCreatures;
}


------------------------------------------------------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void printStatistics(Creatures numCreatures, int curNumCreatures)
{
	string filename;
	
	double totalCost;
	
	cout << "COST OF EACH CREATURE FOR ONE WEEK:\n\n";
	cout << "CREATURE" << setw(15) << "COST";
	for(int i = 0; i < curNumCreatures; i++)
	{
		cout << numCreatures[i].name << setw(5) << "$" << setw(5) << setprecision(4);
		cout << (numCreatures[i].cost.hours * numCreatures[i].cost.hourlyCost + numCreatures[i].cost.foodCost + numCreatures[i].cost.supplyCost);
		totalCost += (numCreatures[i].cost.hours * numCreatures[i].cost.hourlyCost + numCreatures[i].cost.foodCost + numCreatures[i].cost.supplyCost);
		cout << endl << endl;
		cout << "TOTAL COST:" << setw(5) << "S" << setw(5) << totalCost;
	}
}


If anyone could provide any help, it would be much appreciated.
Last edited on
In your print function you're passing a single instance of your class as a parameter but inside the function your trying to treat this single instance as an array.

In future if you only post a couple of snippets you need to correlate your error messages with the snippets posted. For example which line in the snippets provided is line 137 in your actual code?
closed account (48T7M4Gy)
void printStatistics(Creatures[] numCreatures, int curNumCreatures)
Last edited on
For example which line in the snippets provided is line 137 in your actual code?


 
found = moveArrayElements(numCreatures, curNumCreatures, temp);


Sorry, about that.
Last edited on
Topic archived. No new replies allowed.