草庐IT

commentable_type

全部标签

c++ - size of datatype 和 sizeof(data type) 的区别

我在学习C++时遇到了以下问题。我只是一个初学者,我很困惑。sizeof()函数不应该返回数据类型的大小吗?为什么数据对象的大小可能与其sizeof()不同?我不明白答案的解释。假设在一台假想的机器中,char的大小是32位。sizeof(char)会返回什么?一)4b)1c)依赖于实现d)机器相关答案:b说明:标准不要求char为8位,但确实要求sizeof(char)返回1。 最佳答案 sizeof运算符以bytes为单位生成类型的大小,其中字节定义为char的大小。所以根据定义,sizeof(char)始终为1,无论bitsc

c++ - 警告 : 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

我在DebianJessie上使用带有Clang的Qt5。要试验通用lambda,在.pro文件中有:CONFIG+=c++14在构建之后我得到了:warning:'auto'typespecifierisaC++11extension[-Wc++11-extensions]为了摆脱这个明显的信息,我做了:QMAKE_CXXFLAGS+=-Wc++11-extensions但我不断收到明显的信息。为什么?如何隐藏? 最佳答案 根据qmake的存储库历史记录,CONFIG+=c++14节在qmake5.4版中添加:https://co

C++ - 为什么 std::function<some_type_t, void> 无效?

在C++中,如果我尝试这样做:std::function然后编译器会抛出错误。为什么是这样?它在许多情况下很有用。一个例子://g++-std=c++17prblm.cpp#include#includetemplateclasssome_callback{public:usingcallback_t=std::function;some_callback(callback_t_myfunc){this->myfunc=_myfunc;}callback_tmyfunc;};usingcallback_with_just_bool=some_callback;usingcallback

c++ - 同名类之间的共享 vtables : call to virtual method crashes when casting to base type

检查下面的更新,我可以重现并需要帮助。我有一个奇怪的崩溃,其中一些方法在除1个地方之外的任何地方都可以正常工作。这是代码:structbase{virtualwchar_t*get()=0;//canbe{returnNULL;}doesn'tmatter};structderived:publicbase{virtualwchar_t*get(){returnSomeData();}};structcontainer{deriveddata;};//thisisapprox.howitisusedinrealprogramvoidoutput(constbase&data){data

c++ - 这个‘type variableofType()’是函数还是对象?

#includeclassname{public:inta;name():a(0){};};voidadd(name*pname){pname=NULL;}intmain(){namevarName();name*pName=newname();add(pName);add(&varName);//errorC2664:'add':cannotconvertparameter1from'name__cdecl*)(void)'to'name*'} 最佳答案 错误在主函数的第一行:namevarName();您不是使用默认构造函数创建

java - Spring @Value TypeMismatchException :Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'

我想用@Value注解注入(inject)一个Double属性如:@ServicepublicclassMyService{@Value("${item.priceFactor}")privateDoublepriceFactor=0.1;//...并使用Spring属性占位符(属性文件):item.priceFactor=0.1我得到异常:org.springframework.beans.TypeMismatchException:Failedtoconvertvalueoftype'java.lang.String'torequiredtype'java.lang.Double'

java - Spring @Value TypeMismatchException :Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'

我想用@Value注解注入(inject)一个Double属性如:@ServicepublicclassMyService{@Value("${item.priceFactor}")privateDoublepriceFactor=0.1;//...并使用Spring属性占位符(属性文件):item.priceFactor=0.1我得到异常:org.springframework.beans.TypeMismatchException:Failedtoconvertvalueoftype'java.lang.String'torequiredtype'java.lang.Double'

c++ - '从 some_type** 到 const some_type** 的无效转换'

我有一个函数需要constsome_type**作为参数(some_type是一个结构,函数需要一个指向这种类型数组的指针).我声明了一个some_type*类型的局部变量,并对其进行了初始化。然后我将该函数称为f(&some_array),编译器(gcc)说:error:invalidconversionfrom‘some_type**’to‘constsome_type**’这里有什么问题?为什么我不能将变量转换为常量? 最佳答案 参见:Whycan'tIpassachar**toafunctionwhichexpectsaco

c++ - 从 type_id_with_cv<>()::pretty_name() 移除命名空间

我正在使用以下代码来检索类的名称:templatestringGetName(constT&object){usingtype=typenameremove_const::type>::type;returnboost::typeindex::type_id_with_cvr().pretty_name();}代码运行良好。但是,返回的字符串还包含namespace。有没有只返回类名的boost函数?我知道我可以自己写,重点是不要重新发明轮子。 最佳答案 这是轮子的另一项发明和可怕但快速的解决方案,基本上,利用命名空间结构和目录结构

c++ - Python API C++ : "Static variable" for a Type Object

我有一个关于静态变量和TypeObjects的小问题。我使用APIC包装一个c++对象(我们称它为Acpp),它有一个名为x的静态变量。让我们将我的TypeObject称为A_Object:typedefstruct{PyObject_HEADAcpp*a;}A_Object;TypeObject作为“A”附加到我的python模块“myMod”。我已经定义了getter和setter(tp_getset),这样我就可以从python访问和修改Acpp的静态变量:>>>importmyMod>>>myA1=myMod.A(someargs...)>>>myA1.x=34#usingth