[TOC]
文章参考:https://blog.csdn.net/a3192048/article/details/82499164
概述
问题:non-const static data member must be initialized out of line
非const的静态值初始化必须在类外。
1 2 3 4 5 6 7
| 正确的写法:
#include<iostream>
int static i = 0; class Base{ }
|
问题:in-class initializer for static data member of type ‘const double’ is a GNU extension
解释链接:http://stackoverflow.com/questions/370283/why-cant-i-have-a-non-integral-static-const-member-in-a-class
类中的静态常量声明只可以是整形。
1 2 3 4 5 6 7
|
#include<iostream> class Base{ const int static i = 0; constexpr double static d = 1.0; };
|
问题:Single-argument constructors must be marked explicitly to avoid unintentional implicit conversions
参考:https://www.cnblogs.com/xudong-bupt/p/3671972.html
在写一个类的时候,如果一个构造器是接收单个参数的,那么最好要加上explicit。
如果不加的话,该构造函数还会拥有类型转换的情形,造成混淆。
解决办法:该构造函数的声明前加上explicit。
问题:Implicit casts should not lower precision
出现这个告警,主要就是进行强制类型转转换的时候,不应该损失精度。如下:
1 2 3 4 5
| feature /= mFeatureCache.size();
feature /= static_cast<float >(mFeatureCache.size());
|
问题三:undefined reference to pthread_getname_np
问题描述如下:
1 2 3 4 5 6 7 8
| /home/frewen/03.ProgramSpace/15.CLang/01.WorkSpace/NyxCLang/AliceVisionAbility/aura-aurautils/test/TestThread.cpp:39: undefined reference to `pthread_getname_np' /usr/bin/ld: /home/frewen/03.ProgramSpace/15.CLang/01.WorkSpace/NyxCLang/AliceVisionAbility/aura-aurautils/test/TestThread.cpp:48: undefined reference to `pthread_setname_np' /usr/bin/ld: /home/frewen/03.ProgramSpace/15.CLang/01.WorkSpace/NyxCLang/AliceVisionAbility/aura-aurautils/test/TestThread.cpp:55: undefined reference to `pthread_getname_np' /usr/bin/ld: /home/frewen/03.ProgramSpace/15.CLang/01.WorkSpace/NyxCLang/AliceVisionAbility/aura-aurautils/test/TestThread.cpp:65: undefined reference to `pthread_create' /usr/bin/ld: /home/frewen/03.ProgramSpace/15.CLang/01.WorkSpace/NyxCLang/AliceVisionAbility/aura-aurautils/test/TestThread.cpp:69: undefined reference to `pthread_getname_np' /usr/bin/ld: /home/frewen/03.ProgramSpace/15.CLang/01.WorkSpace/NyxCLang/AliceVisionAbility/aura-aurautils/test/TestThread.cpp:75: undefined reference to `pthread_getname_np' /usr/bin/ld: /home/frewen/03.ProgramSpace/15.CLang/01.WorkSpace/NyxCLang/AliceVisionAbility/aura-aurautils/test/TestThread.cpp:84: undefined reference to `pthread_getname_np' /usr/bin/ld: /home/frewen/03.ProgramSpace/15.CLang/01.WorkSpace/NyxCLang/AliceVisionAbility/aura-aurautils/test/TestThread.cpp:89: undefined reference to `pthread_join'
|
在linux上执行gcc thread.c, 结果出现编译错误undefined reference to ‘pthread_create’。由于pthread库不是标准linux库, 所以出错。 改为gcc thread.c -lpthread 即可。
如果你使用cmake进行编译,你可以使用如下:
1 2
| add_compile_options(-pthread) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|