-1
我在C++類中有兩個非常類似的方法。唯一的區別是內部調用的Objective-C方法:避免目標中的重複代碼C
void MyClass::loadFromImage(UIImage *image)
{
// ... Prepare dictionary and error
GLKTextureInfo* info = [GLKTextureLoader textureWithCGImage:image.CGImage options:options error:&err];
// ... Use GLKTexureInfo to load a texture
}
void Surface::loadFromImage(const char* imageName)
{
// ... Prepare dictionary and error
GLKTextureInfo* info = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&err];
// ... Use GLKTexureInfo to load a texture
}
如何組合這兩種方法以減少冗餘代碼?
我希望能做類似於this thread的東西,但不知道Objective-C中的語法應該如何處理。謝謝你的幫助!
Objective-c沒有泛型。你無法實現他們在該主題中的建議。 – CrimsonChris 2014-09-03 17:44:50