草庐IT

exception_type

全部标签

c++ - cmake -D <变量> :<type>=<value> what does the parameter "-D" mean

我正在尝试使用cmake安装opencv。在opencv说明页面中,我找到以下示例:cd~/opencvmkdirreleasecdreleasecmake-DCMAKE_BUILD_TYPE=RELEASE-DCMAKE_INSTALL_PREFIX=/usr/local..据我了解,我应该在我创建的新目录中使用cmake生成Makefile,在这个例子中应该是~/opencv/release。但我不太明白最后一行。在cmake帮助中,我发现:cmake-D:==createacmakecacheentry这是什么意思?特别是这部分:":=",我不明白为什么这个例子给出了"CMAKE

c++ - "except that a default constructed array is not empty"是什么意思?

在N3337中,我正在阅读§23.3.2.1/3,它指出:Anarraysatisfiesalloftherequirementsofacontainerandofareversiblecontainer(23.2),exceptthatadefaultconstructedarrayobjectisnotemptyandthatswapdoesnothaveconstantcomplexity.在§23.2.1,表96容器要求中,它显示了一个默认构造的对象Xu;,其中后置条件是u.empty()。据推测,以下内容:std::arraya;应该导致a.empty()输出1,它确实如此。

C++ : Different deduction of type auto between const int * and cont int &

这里是代码示例。a.intii=0;b.constintci=ii;c.autoe=&ci;-->eisconstint*d.auto&f=42;-->invalidinitializationofnon-constreferenceoftype‘int&’fromanrvalueoftype‘int’e.constauto&g=42-->ok观察:1.对于c)子句,自动推导类型const2.对于子句d),不会自动推导出类型const3.对于条款e),必须手动添加类型const才能使其工作。为什么子句c而不是d会自动推导类型const? 最佳答案

c++ - 如果在 user.hpp 中定义了 BOOST_NO_EXCEPTIONS,为什么不能编译 boost::shared_ptr

我有一个嵌入式系统,想在这个系统中使用boost,但需要禁用异常,因为我不想支付异常成本。boost给了一个user.hpp和可设置的宏选项BOOST_NO_EXCEPTIONS和BOOST_NO_EXCEPTION_STD_NAMESPACE,但是boost::shared_ptr不能编译(更准确的说,不能链接)如果定义了这两个宏。shared_ptr_boost.cpp:(.text._ZN5boost6detail12shared_countC2IiEEPT_[_ZN5boost6detail12shared_countC5IiEEPT_]+0x7a):undefinedrefe

c++ - 循环依赖 : can't delete an incomplete type

我不明白为什么会出现此编译器错误:errorC2027:useofundefinedtype'GameState'note:seedeclarationof'GameState'errorC2338:can'tdeleteanincompletetypewarningC4150:deletionofpointertoincompletetype'GameState';nodestructorcalled这是相关代码:#pragmaonce#include#include"SpawnManager.h"#include"Resource.h"#include#includeclassGa

c++ - 转发声明/包含在模板类中 - "invalid use of incomplete type"

我正在尝试制作一个模板类,其中有一个函数接受该模板的特定实例。我做了以下人为的例子来说明这一点。比方说,我有一个标有模板化(通用)数据类型的个人世界。我有一个特定的个体,称为国王。所有个人都应该能够在国王面前下跪。一般来说,个人可以被标记为任何东西。国王用数字标记(第1、2位国王)。错误g++-g-O2-Wall-Wno-sign-compare-Iinclude-DHAVE_CONFIG_H-c-oIndividual.oIndividual.cppg++-g-O2-Wall-Wno-sign-compare-Iinclude-DHAVE_CONFIG_H-c-oKing.oKing

c++ - "member of type foo has private copy constructor"错误 : why's it an error?

我试图定义这样一个类:#includeclassmy_class{private:someone_elsesfoo;public:myclass();~myclass();//...};但是编译器失败了:“someone_elses类型的字段foo有一个私有(private)的复制构造函数”。现在我知道我可以通过以下方式解决这个问题:classmy_class{private:someone_elses*foo;//...};my_class::my_class(){foo=newsomeone_elses();}my_class::~my_class(){deletefoo;}我的问

c++ - 编译错误 : unresolved overloaded function type

我尝试用g++4.7.2编译以下内容:templatestructA{structB{Tt;templateTget(){returnthis->*M;}};Bb;Tget(){returnb.get();}};intmain(){Aa;a.get();}它给了我test.cpp:Inmemberfunction‘TA::get()’:test.cpp:15:23:error:expectedprimary-expressionbefore‘)’tokentest.cpp:Ininstantiationof‘TA::get()[withT=int]’:test.cpp:22:8:req

c++ - 错误 : aggregate 'first one' has incomplete type and cannot be defined

我写了这个头文件(header1.h):#ifndefHEADER1_H#defineHEADER1_Hclassfirst;//intsumm(inta,intb);#endif和这个源文件(header1.cpp和main.cpp):#include#include"header1.h"usingnamespacestd;classfirst{public:inta,b,c;intsum(inta,intb);};intfirst::sum(inta,intb){returna+b;}#include#include"header1.h"usingnamespacestd;firs

c++ - 与 std::current_exception 关联的数据的生命周期

考虑以下代码:std::exception_ptreptr{std::current_exception()};constchar*msg=0;try{if(eptr!=std::exception_ptr{}){std::rethrow_exception(eptr);}}catch(conststd::exception&ex){msg=ex.what();}我可以在catch之外使用msg吗?换句话说,ex是否引用与eptr相同的异常实例?谢谢! 最佳答案 rethrow_exception的描述说:Throws:theexc