views:

37

answers:

1

Hi all,

Is it possible to use vectors in Coca Touch? If so, what library must be included?

I was following a general C tutorial on them an the only thing needed was to #include <vector>

But XCode states that there is no such file or directory.

Any pointer to a library that provides such functionality is appreciated.

Regards ~dhp

+3  A: 

Objective-C is a superset of C, and therefore anything C will work with them. However, std::vector is a C++ class, which means the compiler has to be aware that you're going to use C, Objective-C and C++ code inside your program. You can do so by changing the extension of your source files from .m to .mm.

However, if you're still at the stage of learning Objective-C or C++, try to not mix too much C++ with it. C++ uses "non-POD types" (POD being "plain old data"), which are inherently incompatible with functions that take variadic arguments; under the hood, all Objective-C calls work that way, so that can make it complex to work with C++ types through Objective-C calls if you're not too sure about how it all works. You could use Cocoa's NSMutableArray class too.

zneak
@zneak, thank you for the great response. I have worked with ObjC for quite a while but have never needed to go into C++ (at all in life, and that after going through Basic / Pascal / Fortran / VB.Net / C# / ObjC and lately Java (just as I 'm getting into android) But after all that I'm still scared of C++ :( btw, this is the library I want to play with: http://wiki.secondlife.com/wiki/Color_conversion_scripts Regards and thanks again big time
dhomes
@dhomes These aren't the STL vectors, but rather some third-party vector objects. The language doesn't look like C either. What they use is roughly equivalent to `struct vector { float x, y, z; };` And this is POD, so feel free to throw it in Objective-C calls.
zneak