我遇到了一种情况,我在常量文件中声明多个相关的 typedef 枚举
:
typedef enum
{
AnimalTypeBear,
AnimalTypeBunny,
MemeTypeCount
}
AnimalType;
typedef enum
{
FishTypeSalmon,
FishTypeTrout,
FishTypeCount
}
FishType;
现在我想为名为 type
的初始化程序定义一个参数,它可以将这两个 typedef 枚举
作为参数。我目前将类型定义为 NSUInteger
,无论我将哪种类型发送到初始化程序中,我都会得到 0(即 FishTypeTrout 应该是 1,但它是 0)。 type
应该使用什么类型的对象才能同时用于 在此处输入代码
typeDef 枚举?
最佳答案
我不是 100% 确定你在问什么,但我尝试了以下代码:
typedef enum AnimalType : NSUInteger
{
AnimalTypeBear,
AnimalTypeBunny,
MemeTypeCount
} AnimalType;
typedef enum FishType : NSUInteger
{
FishTypeSalmon,
FishTypeTrout,
FishTypeCount
} FishType;
void TestFunction(NSUInteger at)
{
printf("at = %d\n",at);
}
当我调用 TestFunction(FishTypeTrout);
这有帮助吗?
关于iphone - 在 Objective-C 中将 TypeDef 作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13078078/