how to write template

Viking* Viking::createWithSpriteFrameName(const char pszSpriteFrameName) {
CCSpriteFrame
pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()>spriteFrameByName;
char msg[256] = ;
sprintf;
CCAssert;
Viking *pobSprite = new Viking;
if )
{
pobSprite
>init();//create with 这个方法可能要重写
pobSprite->autorelease();
return pobSprite;
}
CC_SAFE_DELETE(pobSprite);
return NULL;
}

i have many Class live Viking ,which is inherit CCSprite. they have same method createWithSpriteFrameName() ,class name is different ,how to simple to write once . using Templete class/function ,or define macro,…? can you give out code?