草庐IT

constructor_arguments

全部标签

c++ - "Invalid template argument"错误在 Visual Studio 但不是 GCC

假设你有代码templateclassBaseType>classEST16:publicBaseType{public:EST16(doubled){}};templateclassSCEST{Ty;};typedefEST16EST16_SC;classChild:publicEST16_SC{public:Child():EST16_SC(1.0){}};classNotWorkingChild:publicEST16{public:NotWorkingChild():EST16(1.0){}};TEST(TemplateTest,TestInstantiate){Childch

c++ - connect() 返回 "invalid argument"和 ipv6 地址

我有这个简单的客户端-服务器应用程序对。代码非常简单,我只使用新的建议方法,如getaddinfo等,一切都适用于ipv4。即使对于ipv6环回(::1)它也有效。当涉及到其他一些ipv6地址时,问题就开始了……我在一个网络中有两台机器,当我传递它们的ipv4地址时一切正常,但是当我给我的客户端ipv6地址时,我在连接函数上遇到错误:参数无效.嘿,我不是已经知道了吗?我愿意!当我尝试ping6这个ipv6地址时,我得到了同样的错误:connect:Invalidargument但是有一种方法可以克服这个障碍-应该选择一个带有-I开关的接口(interface),从那时起一切都可以顺利运

C++为什么vector初始化会调用copy constructor

当你用下面的方式初始化一个vector时:std::vectorMyVec(10);它调用默认构造函数一次,然后再调用复制构造函数10次。所以,如果我没理解错的话,vector中的对象都是拷贝构造函数生成的。有人可以解释调用复制构造函数而不是默认构造函数的原因吗?或者甚至只是在没有对象的情况下分配内存? 最佳答案 它将分配没有对象的内存,除非您指定初始大小为10,因此它必须创建10个对象。如果你想要存储10个对象而不实际创建它们,你可以这样做:std::vectorMyVec;MyVec.reserve(10);如果你看一下你正在使

c++ - 错误 : ‘list’ is not a member of ‘std’ and error: template argument 2 is invalid

我正在尝试编译我的头文件,但我遇到了我无法弄清楚的错误。我想创建一个包含3个映射的结构:-从单个单词映射到计数-从词对映射到计数-从单个单词映射到后续单词列表我的头文件中的代码:#include#include#include#include#include#include#include#includetypedefstruct{std::mapfirstCounts;std::mappairCounts;std::map>follows;//Youcanuseaniteratortoretrievethevaluesstoredinthelist.}LanguageModel;我得

c++ - C++ 是否为纯虚拟类创建默认值 "Constructor/Destructor/Copy Constructor/Copy assignment operator"?

C++编译器是否为这个“类”生成默认函数,如Constructor/Destructor/Copy-Constructor...?classIMyInterface{virtualvoidMyInterfaceFunction()=0;}我的意思是不可能实例化这个“类”,所以我认为没有生成默认函数。否则,人们会说您必须使用虚拟析构函数。这意味着如果我不定义析构函数virtual它将默认创建,而不是virtual。此外,我想知道为纯虚拟接口(interface)定义虚拟析构函数是否合理,如上所示?(所以这里没有使用指针或数据,所以不需要破坏任何东西)谢谢。 最

c++ - 铿锵错误 : non-type template argument refers to function that does not have linkage -- bug?

我有一些非常简单的(C++11)代码,最新的clang(version3.4trunk187493)无法编译,但GCC编译正常。代码(下面)实例化函数模板foo使用局部函数类型Bar然后尝试将其地址用作类模板Func的非类型模板参数:templatestructFunc{};templateexterninlinevoidfoo(){usingFoo=Func>;}intmain(){structBar{};//function-localtypefoo();return0;}clang发出以下错误:error:non-typetemplateargumentreferstofunct

c++ - 复制省略 : move constructor not called when using ternary expression in return statement?

考虑以下示例:#includeclassobject{public:object(){printf("constructor\n");}object(constobject&){printf("copyconstructor\n");}object(object&&){printf("moveconstructor\n");}};staticobjectcreate_object(){objecta;objectb;volatileinti=1;//With#if0,object'scopyconstructoriscalled;otherwise,itsmoveconstructor

c++ - 错误 C2064 : term does not evaluate to a function taking 0 arguments

各位!我在一个map容器中维护一组channel数据,从中可以通过channel名称访问单个channel数据。对此,我写了一个简单的函数GetIRChannelData(请看下面的代码)。编译时,语句pusIRChannelData=cit->second();抛出错误,显示为errorC2064:termdoesnotevaluatetoafunctiontaking0arguments所有要做的功能就是在map容器中搜索给定的channel名称/ID,如果找到则将其数据指针分配给时间指针。你能告诉我哪里出了问题吗?constArray2D*GetIRChannelData(std

c++ - 模板参数不明确 : could not deduce template argument

我正在做一些看起来像这样的包装器:#includetemplatevoidApply(void(T::*cb)(Value),T*obj,Valuev){(obj->*cb)(v);}classFoo{public:voidMyFunc(constint&i){std::cout我收到这个错误:应用:未找到匹配的重载函数。voidApply(void(__thiscallT::*)(Value),T*,Value):模板参数Value不明确,可能是int或constint&。voidApply(void(__thiscallT::*)(Value),T*,Value):无法从const

c++ 类继承,未定义对 'Class::Constructor()' 的引用

编辑:在底部发布固定代码。感谢大家的帮助!我刚刚学习C++,但在继承方面遇到了麻烦。我已经搜索和搜索并尝试了所有可能的方法,但我无法在保留我希望它具有的功能的同时编译此代码。我觉得我犯了一个愚蠢的错误,或者我可能只是错过了一些重要的概念,但如果有人能看一下它,我将非常感激!如果我注释掉StarSystemConstructor中创建对象的3行,那么它会编译,所以我知道这与问题有关。#include#include#include#include#includeusingnamespacestd;classSystemBody{public:SystemBody();intsystemb