2011年5月23日 星期一

C++ template in Objective C++

Vector3D.h
template(class Type)
class cMVector3D
{
public:
    Type x;
    Type y;
    Type z;
   
public:
    //--------------------------------
    // @breif: Constructor
    //--------------------------------
    cMVector3D(): x(0), y(0), z(0) {};
   
    //--------------------------------
    // @breif: Destructor
    //--------------------------------
    ~cMVector3D() {};
};



main.mm   --- if your program is objective c  hybrid with c++, you need to rename your file ext. from *.m to *.mm.

#import "MVector3D.h"

int main(int argc, char *argv[]) {
   
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   
    cMVector3D(float)  testV;   ~~~template success
          
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;


Reference:
http://hi.baidu.com/184367426/blog/item/4324263a5ac76e2f71cf6c7c.html

沒有留言:

張貼留言