解决QT提示No previous extern declaration for non-static variable 'sss'

原文链接: https://blog.csdn.net/qq_20515461/article/details/87929540

之前定义全局变量:
1、在1.cpp文件直接写例如 int test;

2、如果2.cpp需要使用test时,一般我会直接在2.cpp直接加extern int test;

其实这是不规范的,
规范的写法:在1.h中写extern int test,然后在2.cpp包含1.h

如果int test只在1.cpp中使用,应该定义为static int test;

所以关于No previous extern declaration for non-static variable 'sss'这个问题,解决方案有两个
方案1、在1.h头文件给报错的变量分别加上 extern声明 ,如extern int test

方案2、在1.cpp给报错的变量加上static (这样只能在该cpp文件使用)
————————————————
版权声明:本文为CSDN博主「清凉简装」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_20515461/article/details/87929540

猜你喜欢

转载自blog.csdn.net/youygq/article/details/102779358
sss