草庐IT

有问必答

全部标签

c++ - 前向声明 : incomplete type 'enums::Category' used in nested name specifier 有问题

我想要一个围绕枚举的包装器,这将使我有机会将其转换为字符串,反之亦然。基类如下:templateclassStringConvertedEnum{public:staticstd::stringtoString(TEnume);staticTEnumtoEnum(std::string&str);protected:staticconststd::map_stringMapping;staticconststd::map_enumMapping;};然后我想要这样的东西:classCategory:publicStringConvertedEnum{public:enumEnum{Ca

c++ - 我的太阳系有问题

所以,这是我的问题。我应该做一个以太阳为中心,行星围绕旋转的太阳系;每个行星都应该有自己的卫星。所以,我都做了,但我做不到地球自转...地球绕太阳自转,月球绕地球自转...我怎么能让地球自转?当我在代码中放置另一个“glrotating”命令时,月球坠落地球或发生一些奇怪的事情......下面是我的代码...//EARTH//INFO:1)it's3rdplanetfromtheSun;//2)it's5thlargestplanetintheSolarSystem,withanequatorialradiusof6378.388km;//3)it's3rdfastestplanet,

c++ - 安装Ogre sdk 有问题?

我是Ogre的新手并尝试运行第一个教程,但我遇到了获取错误信息OGREEXCEPTION(6:FileNotFoundException):'resources_d.cfg'filenotfound!inConfigFile::loadat../../OgreMain/src/OgreConfigFile.cpp(line83)请帮忙,它很关键!另一个问题:cmake对于安装Ogresdk重要吗? 最佳答案 在使用cmake编译/安装ogre之后在Linux上,这两个配置文件位于/usr/local/share/OGRE/resou

c++ - 这个 C++ 转换为枚举有问题吗?

给定以下代码:enumOptions{Surf=0x01,Out=0x02};Optionsall=(Options)(Surf|Out);这个选角有问题吗?如果这个转换有意义,那为什么?根据我的理解,Options只定义了两个变量。值0x03有何意义? 最佳答案 Doesthiscastinghaveproblems?没有。Ifthiscastingmakesense,thenwhy?Basedonmyunderstanding,Optionsonlydefinestwovariables,howthevalue0x03makes

c++ - remove_if 有问题(删除几次后停止删除)

下面的代码想要获取一个字符串并只输出英文字母表中的小写字母。stringsimplifyString(stringword){word.erase(remove_if(word.begin(),word.end(),[](charletter){return!isalpha(letter);}));transform(word.begin(),word.end(),word.begin(),tolower);returnword;}intmain(){strings="a.b.c.d.e.f.g.h.";cout输出为:abcdefgh.f.g.h。所以代码工作然后停止工作。这到底是怎

c++ - 从 1 开始数组索引有问题吗?

我的老师通常从一个开始索引数组。所以,基本上,当我们需要他使用的100个元素的数组时inta[101]代替inta[100]例如,他是这样填写的:for(inti=1;i>a[i];使用这种方法有什么问题吗,或者我应该避免使用它吗?(我在使用从0开始的索引时没有任何问题) 最佳答案 ShouldIusethisregularly,orshouldIavoidit?你应该避免它。一个问题是99.9%的C++开发人员不会与您和您的老师分享这个坏习惯,因此您会发现他们的代码难以理解,反之亦然。但是,还有更严重的问题。这样的索引将与任何标准

c++ - 使用 std::weak_ptr 和别名构造函数打破循环引用:听起来还是有问题?

我还没有在任何主要的C++论坛/博客(例如GotW)上找到以下打破循环引用的方法,所以我想问一下该技术是否已知,其优缺点是什么?classNode:publicstd::enable_shared_from_this{public:std::shared_ptrgetParent(){returnparent.lock();}//thegetterfunctionsensurethat"parent"alwaysstaysalive!std::shared_ptrgetLeft(){returnstd::shared_ptr(shared_from_this(),left.get())

c++ - 详细命名空间中的 using 指令是否有问题?

考虑这个库头:#include#include#includenamespaceLib{namespacedetail{usingnamespacestd;templatevoidsort_impl(istream&in,ostream&out){vectorv;{intn;in>>n;v.resize(n);}for(auto&i:v)cin>>i;sort(v.begin(),v.end());for(autoi:v)out(std::cin,std::cout);}}在此示例中,detail命名空间是否成功地将库的客户端(以及库的其余实现)与using-directive隔离开来

c++ - std::chrono::duration_cast - GCC 实现有问题吗?

我想我在std::chrono::duration_cast的GCC实现中发现了一个错误。谁能证实我这一点?测试代码:usingTicks=std::chrono::duration>>;usingdur=typenamestd::chrono::system_clock::duration;intmain(){std::chrono::time_pointearliest{std::chrono::duration_cast(std::chrono::time_point::max().time_since_epoch())};autoticks=std::chrono::time_

c++ - 通过初始化列表调用另一个类的构造函数。有问题

这是我的示例代码:#includeusingnamespacestd;classBase{public:Base(intv,charz){x=v;y=z;};intx;chary;};classBar{public:Bar(intm,charn):q(m),s(n),base(q,s){};Basebase;intq;chars;};intmain(){BarbarObj(5,'h');cout为什么我得到的输出是0?http://ideone.com/pf47j另外,一般来说,在另一个类中创建成员对象并调用该对象的构造函数的正确方法是什么,就像上面对classBase的对象base所