草庐IT

default-value

全部标签

c++ - "vtable"链接器错误(涉及带有 "=default"的虚拟析构函数)- Clang 3.1 中的潜在错误?

我的代码中出现链接器错误。我已将其精确定位为以下最基本的要点。这段代码给出了链接器错误"vtableforFoo",referencedfrom:Foo::Foo()classFoo{public:Foo();virtual~Foo()=default;};Foo::Foo(){}但是这段代码没有给出任何错误:classFoo{public:Foo();virtual~Foo(){}};Foo::Foo(){}为什么?我认为=default基本上应该和那些空方括号做同样的事情。更新:我正在使用“AppleLLVM编译器4.1”,它是Xcode4.5.2的一部分。这可能是这个编译器中的错

c++ - 如何在获得 future 值(value)后重用 boost::promise 对象?

voidsss(boost::promise&res){res.set_value("hi");}voidyyy(boost::promise&res){res.set_value("hello");}intmain(){boost::threadth;boost::promisea;th=boost::thread(sss,boost::ref(a));th.join();std::cout我收到promise已经满足的错误。如何复用同一个Promise对象? 最佳答案 用未使用的promise替换它:a=boost::promi

.net - 警告 C4341 - 'XX' : signed value is out of range for enum constant

在编译我的C++.Net应用程序时,我收到104条警告类型:WarningC4341-'XX':signedvalueisoutofrangeforenumconstantXX可以在哪里字符长位二进制GUID...无论我做什么,我似乎都无法删除这些警告。当我双击它们时,它会将我带到使用OdbcParameters的代码的一部分-当我尝试使用我的所有其他东西但没有OdbcParameters的测试项目时,它不会发出警告。知道如何摆脱这些警告吗?他们从我实际上很难看到的代码中发出真正的警告-知道我的应用程序有104个警告让我感觉很糟糕! 最佳答案

c++ - 模板函数 : default construction without copy-constructing in C++

考虑structC{C(){printf("C::C()\n");}C(int){printf("C::C(int)\n");}C(constC&){printf("copy-constructed\n");}};还有一个模板函数templatevoidfoo(){//default-constructatemporaryvariableoftypeT//thisiswhatthequestionisabout.Tt1;//willbeuninitializedfore.g.int,float,...Tt2=T();//willcalldefaultconstructor,thenco

c++ - JsonCpp - 当有一个 json::Value 对象时,我怎么知道它的键名?

假设我有这个Json文件:[{"id":0}]使用jsoncpp,我可以通过这样做得到一个Json::Value对象:Json::Valuenode=root[0u]["id"];好的,在代码的其他地方,我正在获取那个node对象,我想从中获取一些信息。我可以得到它的值(value),像这样:intnode_value=node.asInt();但是我怎样才能得到它的名字呢?(即“id”)。它应该是这样的:stringnode_name=node.Name();//ormaybe:stringnode_name2=node.Key();但我找不到类似的东西。帮助?如何获取节点的名称?

c++ - 错误消息 : 'value_type' : is not a member of

我不明白这个神秘的错误消息,但我得到了30个`'value_type':isnotamemberof'TextFileLineBuffer'`当我在VC++6中编译以下代码时,//***行未注释。当然,如果我把它注释掉,它编译得很好。我想我在过去的两个小时里尝试了各种尝试,但都没有成功。任何提示将不胜感激。#include#include#include#include#include#include//wrapperforastringlinestructTextLine{std::stringm_sLineContent;operatorstd::stringconst&()con

c++ - 通过 const reference 或 by value 传递 int,有什么区别吗?

这个问题在这里已经有了答案:Isitcounter-productivetopassprimitivetypesbyreference?[duplicate](7个答案)关闭7年前。当我将int和double之类的原语传递给函数时,是通过constreference传递它们更好,还是通过值传递它们更好(假设我不更改变量的值)?intgetValueFromArray(intindex){//returnthevaluefromthearray}intgetValueFromArray(constint&index){//returnthevaluefromthearray}谢谢

c++ - 将代码从 C++03 迁移到 C++11 : should I be cautious about the implicit default move constructor?

我有一个代码库,我想从C++03切换到C++11。据我所知,某些类将通过具有隐式默认移动构造函数(以及随之而来的移动赋值运算符)而从更改中受益。虽然我完全同意(我什至认为这是一件好事),但我有点担心这种隐式构造函数可能对我拥有的某些不可复制类产生的影响。我举的一个例子是一个类,它包装了libiconv的iconv_t句柄以利用RAII。更明确地说,类如下:classiconv_wrapper{public:iconv_wrapper():m_iconv(iconv_open()){}~iconv_wrapper(){iconv_close(m_iconv);}private://Not

c++ - 从 back_insert_iterator 中提取容器的 value_type 的特征类

std::back_insert_iterator的value_type等于void,但它还有一个protected成员container包含指向底层Container的指针。我正在尝试编写一个traits类来提取容器的value_type,如下所示:#include#include#includetemplatestructoutit_vt:OutputIt{usingself_type=outit_vt;usingvalue_type=typenamestd::remove_pointer_t().container)>::value_type;};intmain(){std::v

c++ - *v8::String::Utf8Value(args[0]->ToString()) 不返回 node.js 插件参数的字符串

我发现*v8::String::Utf8Value(args[0]->ToString())在Node0.8.232位上返回正确的字符串,但在Node0.8上不返回正确的字符串。8个64位。有人知道为什么吗?我的node.js插件看起来像这样:#defineBUILDING_NODE_EXTENSION#include#defineMAX_OUTPUT_BUF80extern"C"char*do_sqlsig(char*in);usingnamespacev8;HandleSqlsig(constArguments&args){HandleScopescope;char*c_arg,*