草庐IT

default-public

全部标签

c++ - 错误 C2512 : no appropriate default constructor available

我收到这个烦人的错误,我不知道为什么=(!这是问题,我解决了,但构造函数有问题。WriteaprogramthatdefinesaclasscalledCirclethatincludesradius(typedouble)asdatamembers.Provideasetandagetfunctionforthisdatamember.Ensurethatthevalueenteredbytheuserisvalidandcorrect(greaterthanzero).Includefunctionmembers:a.functionmemberthatcomputeandretu

c++ - 多级私有(private)和公共(public)继承 - 不寻常的访问

#includeusingnamespacestd;classuvw;classabc{private:intprivateMember;protected:intprotMember;public:intpublicMember;};classdef:privateabc{public:voiddummy_fn();};classuvw:publicdef{};voiddef::dummy_fn(){abcx;defy;uvwz;cout据我了解,在def之后从abc私下继承,protMember和publicMember在def中成为私有(private).所以,现在当uvw继承自

c++ - 我应该使用 std::default_random_engine 还是应该使用 std::mt19937?

当我想使用std::random生成随机数时,我应该更喜欢哪个引擎?std::default_random_engine还是std::mt19937?有什么区别? 最佳答案 对于轻量级随机数(例如游戏),您当然可以考虑default_random_engine.但是,如果您的代码严重依赖于随机性的质量(例如模拟软件),则不应使用它,因为它只提供极简保证:Itisthelibraryimplemention'sselectionofageneratorthatprovidesatleastacceptableenginebehavio

c++ - Visual C++ 中的 "No appropriate default constructor available"错误

我不明白。我一直盯着代码看代码三个小时,我看不出问题。我正在创建的名为TwoDayPackage的类派生自一个名为Package的类。这就是我定义构造函数的方式:TwoDayPackage(string,string,string,string,int,string,string,string,string,int,float,float,float);这是我实现构造函数的方式:TwoDayPackage::TwoDayPackage(stringsName,stringsAddress,stringsState,stringsCountry,intsZIP,stringrName,s

c++ - 用原语 union 公共(public)初始序列

我试图更好地理解一个关于union和通用初始序列规则的相当令人惊讶的发现。常见的初始序列规则说(class.mem23): Inastandard-layoutunionwithanactivememberofstructtypeT1,itispermittedtoreadanon-staticdatamembermofanotherunionmemberofstructtypeT2providedmispartofthecommoninitialsequenceofT1andT2;thebehaviorisasifthecorrespondingmemberofT1werenomin

c++ - 公共(public)访问声明不影响成员函数指针?

我对g++(5.1版)下的访问声明有疑问。classBase{public:voiddoStuff(){}};classDerived:privateBase{public://Usingolderaccessdeclaration(withoutusing)shootsawarning//andresultsinthesamecompilationerrorusingBase::doStuff;};templatevoidexec(C*c,Funcfunc){(c->*func)();}intmain(){Derivedd;//Untilhere,everythingcompiles

c++ - 私有(private) typedef 的公共(public)使用是否可移植?

classSettings{private:typedefstd::mapOptionMap;public:typedefOptionMap::iteratoriterator;typedefOptionMap::const_iteratorconst_iterator;...};此代码可移植吗?关于它的标准规定是什么? 最佳答案 这是合法的,并且Settings::iterator和Settings::const_iterator可供Settings类的所有用户访问。C++中的访问控制纯粹应用于名称。ISO/IEC14882:20

c++ - 跟踪 C++ lib 公共(public) API 更改

我目前正在开发基于C++Qt的大型项目,该项目即将对其公共(public)API进行重大重构,如果有一个工具可以生成有关已添加方法的报告,那就太好了或从构建中移除。我知道有一个用于Java的工具来执行此操作,我认为可能有一个用于.NET的工具,但经过一番搜索后,我无法找到任何用于C++的工具。是否存在。跨平台会很好,或者如果只在Linux中也可以。 最佳答案 如果您使用Doxygen或其他类似工具来记录您的API,那么您可以diff目录。无论如何,这是你应该做的事情。(您也可以告诉Doxygen查找未记录的函数。)您可以轻松地将其应

c++ - "Default member initializer needed within definition of enclosing class outside of member functions"- 我的代码格式不正确吗?

#includestructfoo{intx{0};foo()noexcept=default;voidf()noexcept(noexcept(std::declval())){}};intmain(){}liveexampleongodbolt上面的代码可以用我测试过的任何版本的g++,以及3.6到3.9.1的clang++编译,但是不能用clang++4.0.0编译:test.cpp:6:5:error:defaultmemberinitializerfor'x'neededwithindefinitionofenclosingclass'foo'outsideofmemberf

c++ - 构造函数 : difference between defaulting and delegating a parameter

今天,我偶然发现了thesestandarddeclarationsstd::vector构造函数://untilC++14explicitvector(constAllocator&alloc=Allocator());//sinceC++14vector():vector(Allocator()){}explicitvector(constAllocator&alloc);这种变化可以在大多数标准容器中看到。一个稍微不同的例子是std::set://untilC++14explicitset(constCompare&comp=Compare(),constAllocator&al