草庐IT

add_compiler_flags

全部标签

c++ - 默认模板参数 : Why does the compiler complain about not specifying template argument?

我有这个代码:structA{};templatestructB{voidfoo(){}};Bb;//Error:missingtemplateargumentsbefore'b'//Error:expected';'before'b'//Moreerrorsb.foo()如果我将foo()作为具有相同模板“签名”的模板函数,编译器不会提示没有指定模板参数:structA{};structB{templatevoidfoo(){}};Bb;//OKb.foo()那么为什么我需要为带有默认参数的模板类指定参数,而不是为模板函数指定参数呢?我是否遗漏了一些微妙之处?原因肯定是因为模板参数推

c++ - 错误 : uint64_t was not declared in this scope when compiling C++ program

我正在尝试一个简单的程序来打印steady_clock的时间戳值,如下所示:#include#includeusingnamespacestd;intmain(){cout(steady_clock::now().time_since_epoch()).count();cout但是每当我像这样编译时g++-oabcabc.cpp,我总是会遇到错误:Infileincludedfrom/usr/include/c++/4.6/chrono:35:0,fromabc.cpp:2:/usr/include/c++/4.6/bits/c++0x_warning.h:32:2:error:#er

android - 如何使用 'CMakeLists.txt' 中的 add_library 将整个文件(.cpp、.h 等)包含在目录中

这个问题在这里已经有了答案:AutomaticallyaddallfilesinafoldertoatargetusingCMake?(5个答案)关闭5年前。在我的项目中,我使用的是cpp和.h文件,它们都位于不同的文件夹中|-src|-main|-java|-cpp|-native-lib.cpp|-library-1|-include|-lib11.h|-lib12.h|-...|-library-2|-include|-lib21.h|-lib22.h|-...在当前版本中,我将每个文件添加到'CMakeLists.txt'...add_library(#Setsthenameo

c++ - 在 constexpr 函数中返回一个 C 字符串 : why no warning from the compiler?

考虑以下代码:constexprautof(){autostr="HelloWorld!";returnstr;}intmain(intargc,char*argv[]){staticconstexprautostr=f();std::cout我的编译器不显示任何警告是否正常?它是定义的行为吗?我能保证程序会显示"HelloWorld!"吗?我希望"HelloWorld!"不会超出函数的范围... 最佳答案 在C++中stringliterals有staticstorageduration只要程序运行就可以生存。因此,指向从f返回的

c++ - 为什么 boost::is_same<int const&, boost::add_const<int &>::value 等于 false?

我正在处理"C++TemplateMetaprogramming"byAbrahams&Gurtovoy“这实际上不在第二章中,而是我在做第一个练习(2.10、2.0)时尝试过的,这让我很困惑:#include#includestd::stringdisplay(boolb){return(b?"true":"false");}intmain(){usingnamespacestd;cout::type>::value)输出为“假”。但是,如果我删除引用,即“intconst”和“int”。输出为“真”。 最佳答案 如果你用指针尝试

c++ - 无限循环heisenbug : it exits if I add a printout

这是我的源代码:#include#includeusingnamespacestd;doubleup=19.0+(61.0/125.0);doubledown=-32.0-(2.0/3.0);doublerectangle=(up-down)*8.0;doublef(doublex){return(pow(x,4.0)/500.0)-(pow(x,2.0)/200.0)-0.012;}doubleg(doublex){return-(pow(x,3.0)/30.0)+(x/20.0)+(1.0/6.0);}doublearea_upper(doublex,doublestep){ret

c++ - x86/C++ - 指向指针 : Const being violated by compiler? 的指针

我正在为我的学生项目的游戏引擎开发一个共享指针(称为句柄)实现,我们遇到了一个我们无法解释的错误。出于某种原因,在我们工厂的某个时刻,有一个无效的内部指针通过句柄传递给工厂,这导致我们的原型(prototype)加载期间发生崩溃。我们调试了几个小时的过程,并将任何复杂的语句分解为最简单的版本,以便于调试。我最终将问题归结为Handle类的复制构造函数。但是,似乎仍然存在释放内部指针的中间步骤。我阅读了所有我能找到的关于可能导致此问题的文章,但没有找到任何内容。最后,我决定查看反汇编代码,看看我是否能弄清楚发生了什么。这是没有反汇编的复制构造函数。templateHandle::Hand

c++ - Visual Studio 2012 : C++ compiler ignoring user-specified include directories

我遇到常见错误fatalerrorC1083:Cannotopenincludefile:'afxres.h':Nosuchfileordirectory。搜索引擎为此显示了很多匹配项,但没有一个建议的解决方案对我有用。通常这看起来是路径问题。所以,我确保安装了相关的库,并找到了文件。使用绝对路径作为#include工作正常:#include"C:\ProgramFiles(x86)\MicrosoftVisualStudio11.0\VC\atlmfc\include\afxres.h"但是,如果我将目录(C:\ProgramFiles(x86)\MicrosoftVisualStu

c++ - "The C++ compiler "/usr/bin/c++ "is not able to compile a simple test program."尝试安装 OpenCV 时

我正尝试按照此link在我的Mac上安装OpenCV但是,当我在终端上键入cmake-G"UnixMakefiles"..时,会打印出此错误。--TheCXXcompileridentificationisunknown--TheCcompileridentificationisunknown--CheckforworkingCXXcompiler:/usr/bin/c++--CheckforworkingCXXcompiler:/usr/bin/c++--brokenCMakeErrorat/opt/local/share/cmake-3.0/Modules/CMakeTestCXX

c++ - Const temporary from template type 以及为什么使用 std::add_const?

以下代码摘自cppreference.com.#include#includestructfoo{voidm(){std::coutvoidcall_m(){T().m();}intmain(){call_m();call_m::type>();}但是,当使用VC++Nov2012CTP编译时,输出为Non-cvNon-cv而不是预期的:Non-cvConst另外,下面两个语句有什么区别:call_m();和call_m::type>(); 最佳答案 这似乎是MSVC的一个错误。使用T()形式的表达式(就标准而言,这是一种显式类型转