Game Development Community

Is there an equivalent of C++ template in Objective C 2.0?

by Jean-louis Amadi · in Torque 3D Professional · 06/12/2012 (5:28 am) · 2 replies

I wish know if we can use the "templates" of C++ in Objective C 2.0 or if there is an equivalent?
template <typename T> 
class MyClass
{ 
  Scope:
  Attributes;
  Methodes;
};
If yes, have you some examples or url or tuto at this subject?

Thank you.

#1
06/12/2012 (6:17 am)
@Jean-louis - No, it's not applicable. Template exists in C++ because it is a strongly typed language. Objective-C allows for object declarations without a type. For example, you can use id as a type for a parameter or IB connection. A list in C++ needs to use an explicit type or a template. A list in Objective-C stores objects, so you can use an abstract object type.

If you need to use a templated class in Objective-C, you can create it in C++ and allow parsing of C++ in an Cbjective-C++ file (.mm).
#2
06/13/2012 (1:19 am)
Ok, i will follow the advice with Objective-C++.

Thank you.