StringArray pointer question

I’m trying to retrieve an element from a StringArray pointer and having troubles. I’ve searched the juce files for StringArray pointers as examples without much luck.

I get this error:
error C2664: ‘outputDebugString’ : cannot convert parameter 1 from ‘class juce::StringArray’ to 'const class juce::String &'
Reason: cannot convert from ‘class juce::StringArray’ to ‘const class juce::String’

StringArray* array = new StringArray(); String values = "1 2 3 4 5 6"; array->addTokens (values, false); DBG(array[0]);

I’ve found this workaround, but is there a way to directly retrieve an element from a StringArray pointer?

StringArray* array = new StringArray(); String values = "1 2 3 4 5 6"; array->addTokens (values, false); StringArray array2; array2.addArray (*array, 0, 1); DBG (array2[0]);

Well, you could try either (*array)[0] or array->operator

The operator[] is overloaded for StringArray, not for a pointer to StringArray, so the dereference is necessary.

why pointer anyway?

I use bags of stringarrays and I’ve never needed to “new” one ever.

only pointers I use these days are audio buffers. and even they have a rapper you can stick on the stack and let jules do the pointer management. oh and Components of corse.

and references are your friend!

bodisiw,

Thanks for the reply. Those solutions are what I’m looking for. Been a while since I used C++ and pointers are once again confusing.

Regarding Karbon L. Forms comments about [quote]a rapper you can stick on the stack and let jules do the pointer management[/quote]. Does Juce handle pointers for items on the stack which are Juce types?