Assign str:string to CCArray

Hi all, I have a question is: can I assign a string with a CCArray? And if can, how should I do? This is my code:

void productReceived(CCArray* productArray)
{
	//to do
	std::string productIndentifier1 = productArray[0];
	std::string productPrice1 = productArray[1];
	std::string productTitle1 = productArray[2];
// the three line above throw the error: `no matching function for call to 'std::basic_string<char>::basic_string(cocos2d::CCArray&)'`
}

Any help would be appreciated.

Why not trying std::vector<std::string> ?

1 Like

The same error as before… :frowning:

Can you share productArray’s definition?

CCArray is deprecated: you should use std::vector< objectType > instead, or cocos2d’s Vector if you need the vector’s object to be automatically retained & released.
As for your problem, the mistake is that you are passing a pointer to an object of type CCArray in your function, but then you treat it as if it was an object.
I do not know the CCArray class, so I propose you a fix by using std::vector< std::string > (which you should be using since CCArray is deprecated…).
You can either pass the object via reference (const std::vector< std::string > &array) and use the square brackets or pass it via pointer (like you are doing) and access it via productArray->at(index).
Personally, I would opt for the first choice, as I like square brackets better :smile:.

1 Like