我收到此错误
error: Access.Core may be used uninitialized in this function
这是我的代码:
static int FirstTime = 1;
MyStruct Access;
if (FirstTime) {
FirstTime = 0;
Access = Implementation();
DoSomething(Access);
}
if(Other_Variable) {
Access = Implementation2();
DoSomething(Access);
}
//The Other_Variable will be set to 1 and to 0 by other part of the code
我的代码就是这样,因为我只想第一次调用函数实现。在每次调用中,Access 变量都将被更新,因此将其设为静态没有多大意义。
如果我将 Access 设为静态,但我不喜欢将其设为静态,因为在其他所有调用中,Access 都会被更新。有什么方法可以避免问题而不使其成为静态?
此外,欢迎使用仅执行一次函数而不是使用静态变量的任何更好的选项。