Hi there,
I am fairly new to C++ and wanted to have a go at coding my own function with parameters. However some of the parameters are arrays and I get strange errors occur. I will comment my code with a couple of other questions as well.

I am writing this for an engine so Everything is declared.

Line 6 - Syntax error at "["
Line 10 - Syntax error at "["
Line 14 - Syntax error at "while"
Line 18 - Syntax error at "CreateObject"
#include "k_inc_generic"
#include "k_inc_utility"



int Populate(int Amount, string TagArray[], float xLoc[], float yLoc[], float zLoc[], float Orient[]); //Do I have to declare it like this?



int Populate(int Amount, string TagArray[], float xLoc[], float yLoc[], float zLoc[], float Orient[])
{
	int AutoInc = 0;
	
	while(AutoInc < Amount)
	{
              int a = AutoInc;              

		CreateObject(OBJECT_TYPE_CREATURE, TagArray[AutoInc], Location(Vector(xLoc[AutoInc], yLoc[AutoInc], zLoc[AutoInc]), Orient[AutoInc]);

		AssignCommand(TagArray[AutoInc],ActionRandomWalk());

		AutoInc++;
	}
       return 0;
}

Thanks in advance.

TB12

I don't think that string TagArray needs the '[]'.

I see nothing obviously wrong with the code you've shown. However:

1) You should be aware that writing a parameter of the form string foo[] means exactly the same as if you had written it as string *foo -- that is, the parameter is just a pointer.

2) If you don't have a declaration of the string type in scope, the compiler won't know what it means.

I thought that if it was an array then it had to have that.

I still get the same errors without it though.

EDIT:
just tried replacing [] with * but i get the same errors but with "*" also i don't understand what you mean by

2) If you don't have a declaration of the string type in scope, the compiler won't know what it means.

Does this mean i have to declare them there as well?

And do you have a declaration of the string type in scope?

using the namespace "std" for string?

Just found out that the engine I am using doesn't support arrays.

Thanks anyway guys.

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.