使用了 NULL,但是 NULL 在当前的作用域中没有被声明

 error: ‘NULL’ was not declared in this scope
In file included from /home/topeet/qts/SanliApp/views/laserprams/myuis/myuilaserpublic.h:3,
                 from /home/topeet/qts/SanliApp/views/laserprams/myuis/myuilaserpublic.cpp:1:
/home/topeet/qts/SanliApp/views/mains/../../publics/mocro.h:6:42: error: ‘NULL’ was not declared in this scope
    6 | #define initMy(AType) AType* AType::my = NULL; AType* AType::getMy(){ if(my==NULL){ new AType();} ;return my; };
      |                                          ^~~~
/home/topeet/qts/SanliApp/views/laserprams/myuis/myuilaserpublic.cpp:3:1: note: in expansion of macro ‘initMy’
    3 | initMy(MyUiLaserPublic)
      | ^~~~~~
/home/topeet/qts/SanliApp/views/laserprams/myuis/myuilaserpublic.cpp:2:1: note: ‘NULL’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
    1 | #include "myuilaserpublic.h"
  +++ |+#include <cstddef>
    2 |

错误信息指出在文件 mocro.h 中使用了 NULL,但是 NULL 在当前的作用域中没有被声明。NULL 通常是在 C++ 标准库的头文件 <cstddef> 或 <cstdlib> 中定义的。

根据错误提示,你可以通过在 mocro.h 或在使用 mocro.h 之前包含 <cstddef> 来解决这个问题。这样可以确保 NULL 被正确地定义。

具体修改如下:

  1. 打开 mocro.h 文件。
  2. 在文件的开始部分添加 #include <cstddef>。这行代码应该放在其他包含指令之前,以确保 NULL 在使用前已经被定义。

修改后的 mocro.h 文件应该类似于这样:

#include <cstddef>  // 包含对 NULL 的定义  
#define initMy(AType) AType* AType::my = NULL; AType* AType::getMy(){ if(my==NULL){ new AType();} ;return my; };

或者,如果你不想修改 mocro.h,你也可以在使用这个宏的每个文件中确保包含了 <cstddef>。例如,在 myuilaserpublic.cpp 中:

#include <cstddef>  
#include "myuilaserpublic.h"

这样也能解决问题。选择哪种方式取决于你对项目结构的偏好以及 mocro.h 被使用的广泛程度。如果 mocro.h 被多个文件依赖,建议在 mocro.h 中添加 #include <cstddef>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值