Objective-C error: initializer element is not constant

前端 未结 3 1684
悲哀的现实
悲哀的现实 2021-01-17 17:22

Why does the compiler give me the following error message on the provided code: \"initializer element is not constant\". The corresponding C/C++ code compiles perfectly und

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 18:00

    @dreamlax is correct, you can't have a const declaration whose initialization depends upon another (const) variable. If you need one to depend on the other, I suggest creating a variable that you can treat as a constant and initialize it only once. See these SO questions for details:

    • Defining a constant in objective-c
    • Constants in Objective C

提交回复
热议问题