草庐IT

class_list

全部标签

c++ - G++ 4.5 错误 : No diagnostic for narrowing in initializer list

我尝试了以下代码:intmain(){intx{23.22};}其中包括需要缩小的初始化,但代码编译正常,没有任何错误或警告。另一方面,以下代码给出了错误:intmain(){intx[]{23.22};}我是发现了错误还是什么?PS:我目前使用的是GCC4.5.0 最佳答案 看起来像一个错误。以下直接来自n3092草案:8.5.4List-initialization—Otherwise,iftheinitializerlisthasasingleelement,theobjectisinitializedfromthatelem

c++ - 是否有可能调用一个父类(super class)的构造函数,两个类远离 C++ 中的当前类

我有三个继承如下的类:Class_AClass_B:publicClass_AClass_C:publicClass_BClass_A包含一个构造函数:public:Class_A(constchar*name,intkind);Class_B不包含该构造函数。在Class_C中,我希望调用Class_A的构造函数。像这样的东西:Class_C(constchar*name,intkind):Class_A::Class_A(name,kind){}问题是我无法向Class_B添加中间构造函数,因为Class_B是生成的代码,每次我makeclean时都会重新生成。所以我无法对Clas

c++ - 前向声明的类型和 "non-class type as already been declared as a class type"

我对以下代码有疑问:templatevoidfoo(structbar&b);structbar{};intmain(){}它在GCC上编译成功,但在MSVC(2008)上编译失败并出现以下错误:C2990:“bar”:已声明为类类型的非类类型是代码错误还是MSVC中的错误?如果我在模板定义之前添加structbar;就可以了。 最佳答案 我们有我们的赢家:https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-

c++ - 为什么 boost::assign::list_of 不适用于 pair<string, vector<string>>?

我不明白为什么这不起作用(VisualC++2012):#include#include#include#includeusingnamespacestd;intmain(){pair>("^",boost::assign::list_of("rules"));}错误是:include\utility(138):errorC2668:'std::vector::vector':ambiguouscalltooverloadedfunctionwith[_Ty=std::string]include\vector(786):couldbe'std::vector::vector(std:

c++ - 标准 :forward inside a template class

templateclassBlockingQueue{std::queuecontainer_;templatevoidpush(U&&value){static_assert(std::is_same::type>::value,"Can'tcallpushwithoutthesameparameterastemplateparameter'sclass");container_.push(std::forward(value));}};我希望BlockingQueue::push方法能够处理T类型对象的右值和左值引用,以将其转发到std::queue::push正确的版本。是像上面

c# - 如何向 MFC 应用程序添加 list 并设置支持的操作系统?

我正在尝试为WindowsServer2012运行Microsoft平台就绪测试工具4.6:http://www.microsoft.com/en-ca/download/details.aspx?id=41676我遇到了一个问题。它提示我有一个MFC应用程序有一个list,但该list缺少supportedOS部分。我知道如何将它添加到C#项目中,但如何在MFC应用程序中添加它?MFC应用程序显示在“list中缺少支持的操作系统部分的可执行文件”下。 最佳答案 刚收到。过程如下:右键单击您的解决方案,转到“属性”。从配置属性向下钻

c++ - 错误 : ‘template<class> class std::auto_ptr’ is deprecated

我正在使用scons和ubuntu。当我使用'scons'制作一些程序时,会发生错误,例如,src/db/DBTextLoader.cc:296:3:error:‘templateclassstd::auto_ptr’isdeprecated[-Werror=deprecated-declarations]/usr/include/c++/5/bits/unique_ptr.h:49:28:note:declaredheretemplateclassauto_ptr;这是我的命令;$./configuer$sourcesomething.sh$scons其实我也不知道。我已经在搜索这个

c++ - 对于类型 Class::Type,我可以从 const Class 派生 const Class::Type 吗?

我正在实现一个容器,例如:templateclassContainer{public:usingvalue_type=T;...};是否有从constContainer派生constvalue_type的好方法?背景:我已经通过嵌套模板类实现了迭代器类型:templateclassiterator_base{public:...Value&operator*()const;private:Container*c;};usingiterator=iterator_base;usingconst_iterator=iterator_base;工作正常,但iterator_base的第二个模

c++ - 通过插入保持 std::list 迭代器有效

注意:这不是我应该“使用列表还是双端队列”的问题。这是一个关于迭代器在面对insert()时有效性的问题.这可能是一个简单的问题,我太笨了,看不出正确的方法。我正在实现(无论好坏)网络流量缓冲区作为std::listbuf,并且我将我当前的读取位置保持为迭代器readpos.当我添加数据时,我会做类似的事情buf.insert(buf.end(),newdata.begin(),newdata.end());我现在的问题是,如何保留readpos迭代器有效吗?如果它指向旧buf的中间,那么它应该没问题(由std::list的迭代器保证),但通常我可能已经读取并处理了所有数据并且我有re

c++ - 为什么 list::push_back 在 VC++ 中比在 g++ 中慢得多?

此代码在我的VS2012中大约需要20秒,但在G++中仅需1.x秒。均在win8x64中并使用默认选项编译。listitems;for(inti=0;i是关于内存分配的吗?在我的机器上用VC++输出后释放内存需要3~5秒,而在我friend的(win7x64)上甚至超过1分钟。 最佳答案 嗯...我扩展了您的代码以包含计时:#include#include#include#includeintmain(){std::listitems;clock_tstart=clock();for(inti=0;i我用VC++编译使用:cl/O2