compiler error: conversion to non-scalar type requested

Jun 8, 2012 at 3:55am
I'm a beginning C++ programmer and try as I might, I cannot figure out the following error. I made a class called Fighter and I have two functions that have similar argument lists, but one is compiling fine and the other is not. I am at a loss as to why this is happening.

in int main() I declare two arrays of fighters as so:

1
2
3
4
5
6
7
8
9
10
11
12
Fighter monsters[4] = {
		Fighter("Green Slime", 100, 0, 50, 50, 50, 50),
		Fighter("Green Slime", 100, 0, 50, 50, 50, 50),
		Fighter("Green Slime", 100, 0, 50, 50, 50, 50),
		Fighter("Green Slime", 100, 0, 50, 50, 50, 50)
		};
Fighter party[4] = {
		Fighter("Hero 1", 200, 100, 60, 60, 60, 60),
		Fighter("Hero 2", 200, 100, 60, 60, 60, 60),
		Fighter("Hero 3", 200, 100, 60, 60, 60, 60),
		Fighter("Hero 4", 200, 100, 60, 60, 60, 60)
		};


here is the first function prototype and an example of a function call that works fine:

1
2
3
void battlemenu(Fighter f[], int i);
battlemenu(party,4); // works
battlemenu(monsters,4); // works 


here is the second function prototype and an example of a function call that is coming up with a compiler error:

1
2
bool battle(Fighter player[],int players,Fighter enemy[],int enemies);
battle(party,4,monsters,4); // does not work 


I'm pretty much passing the arrays (technically passing the pointers to the first element of each array, as I understand it) identically in each case. I'm sure I'm doing something wrong; but what? the error I'm getting is as follows:

78JESLKr.c:390: error: conversion from 'Fighter*' to non-scalar type 'Fighter' requested

I know what that error means, but I don't know what's wrong with my code to make it happen. honestly, I'm baffled as to why the battlemenu function works, but the battle function does not - the argument lists look the same to me. I did try using new to allocate the arrays dynamically but that did not help.

any help would be appreciated. I tried to keep this short, but if any other code would help you (like the class definitions), please let me know.
Jun 8, 2012 at 11:37pm
nevermind, in the function prototype I missed the [] after enemy.

hours. so many hours. all over two tiny keystrokes. why do I get the feeling this isn't the last time I'll be saying that?
Topic archived. No new replies allowed.