草庐IT

dependent-type

全部标签

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++ - 我应该担心 "Conditional jump or move depends on uninitialised value(s)"吗?

如果您使用过Memcheck(来自Valgrind),您可能会熟悉这条消息...Conditionaljumpormovedependsonuninitializedvalue(s)我读过这方面的内容,它只会在您使用未初始化的值时发生。MyClasss;s.DoStuff();这会起作用,因为s是自动初始化的...所以如果是这种情况,并且它起作用了,为什么Memcheck告诉我它未初始化?应该忽略该消息吗?也许我误解了错误指向我的位置。从Valgrind手册中,实际的错误片段是......intmain(){intx;printf("x=%d\n",x);}但是,在我的代码中,我看不到

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

c++ - 没有 typedef 的运算符 member_function_pointer_type()?

是否可以在不使用typedef的情况下创建一个operatormember_function_pointer_type()(即通过内联指定成员函数指针的类型)?例如,在实现SafeBoolIdiom时:classFoo{typedefvoid(Foo::*bool_type)()const;public:operatorbool_type()const;};是否可以在声明运算符时直接写出bool_type的类型?如果是,怎么办? 最佳答案 这似乎是唯一不能在不使用typedef的情况下声明(类型转换)operator的情况。如果它是