草庐IT

STL_container_type

全部标签

c++ - 传递的STL容器会生成拷贝吗?

我不记得传递STL容器是否会生成容器的拷贝,或者只是另一个别名。如果我有几个容器:std::unordered_map_hashStuff;std::vector_characterStuff;我想将这些变量传递给一个函数,我可以这样创建函数吗:voidSomeClass::someFunction(std::vectorcharacterStuff);或者这会复制unordered_map/vector吗?我想我可能需要使用shared_ptr。voidSomeClass::someFunction(std::shared_ptr>characterStuff);

c++ - "Template argument for template template parameter must be a class template or type alias template"

templatestructList{};templateclass>structListHelper;templatestructListHelper>{};^/*Error:Templateargumentfortemplatetemplateparametermustbeaclasstemplateortypealiastemplate*/怎么了?我正在使用clang++SVN。 最佳答案 您有一个模板模板参数。您必须传递一个模板作为其参数。您改为将模板实例化作为其参数传递-这是一个具体类,而不是模板(其所有参数均已绑定(bi

c++ - 编译器错误 C4430 : missing type specifier - int assumed

这个问题在这里已经有了答案:Resolvebuilderrorsduetocirculardependencyamongstclasses(12个答案)关闭8年前。我有这个错误:“错误C4430:缺少类型说明符-假定为int。注意:C++不支持default-int”使用此代码示例://A.h#include"B.h"classA{B*b;..};//B.h#include"A.h"classB{A*a;//errorerrorC4430:missingtypespecifier-intassumed.};

c++ - STL 迭代器上下文中的奇异值和非奇异值是什么?

C++标准(2003)的第24.1/5节内容如下:Justasaregularpointertoanarrayguaranteesthatthereisapointervaluepointingpastthelastelementofthearray,soforanyiteratortypethereisaniteratorvaluethatpointspastthelastelementofacorrespondingcontainer.Thesevaluesarecalledpast-the-endvalues.Valuesofaniteratoriforwhichtheexpre

c++ - g++ 4.7.1 编译错误 : conflicting types for ‘strsignal’

我正在尝试在Ubuntu12.0432位上从源代码编译g++4.7.1。目前我已经完全做到了:https://askubuntu.com/questions/168947/how-to-upgrade-g-to-4-7-1除了在编译g++4.7.1之前,它要求我“取消设置LIBRARY_PATH”(所以我已经这样做了)。所以编译开始了,过了一会儿我收到以下错误消息:Infileincludedfrom../.././gcc/c-lang.c:24:0:../.././gcc/system.h:499:20:erreur:conflictingtypesfor‘strsignal’/us

c++ - Vector Add的STL算法

假设我有两个vector小号:vectorfoo{1,2,3};vectorbar{10,20,30};现在我想在它们上面做一个vector相加,结果是:112233是否有可以处理此问题的STL算法,或者我是否需要使用for循环:for(autoi=0;i奖金问题,如果我想做比添加更复杂的事情,比如foo怎么办?是一个vector和bar仍然是vector.我希望,如果有我可以使用的STL算法,它也能支持lambdas? 最佳答案 可以使用std::transform实现您想做的事情.在你的情况下:std::transform(fo

c++ - 您如何组织 STL header ?

我正在从事一个使用STL的大型项目,我对您组织STL的首选方式有疑问#includes.您是否喜欢在使用的源文件中#include每个header。例如,如果两个foo.cpp和bar.cpp需要std::string,那么两者都会#include.您是否希望拥有包含您的项目使用的所有STLheader的单个header文件(即将它们添加到MS“stdafx.h”预编译header)。第一种方法的优点是.cpp文件是一个独立的单元,可以在不同的项目中使用,而不必担心缺少#include。.第二种方法的优点是你可以使用你的编译器预编译头支持加上你可以包装STL#includes在prag

c++ - 如何处理 C++0x STL 中丢失的 'emplace_range'?

我有两个容器,假设它们是这样定义的:std::vector>a;std::vector>b;假设a和b都被填充了。我想使用move语义将整个容器a插入到b中的特定位置,以便unique_ptrmove到b。假设i是指向b中某处的有效迭代器。以下不起作用:b.insert(i,a.begin(),a.end());//error:triestocopy,notmove,unique_ptrs是否有另一种STL算法可以实现这种“move插入范围”?我想我需要一种emplace_range,但VS2010的STL中没有。我不想编写一个一个一个插入的循环,因为每次插入时都会向上movevect

c++ - 如何使用 type_info 进行类型转换?

我存储了一个指向type_info对象的指针。intMyVariable=123;conststd::type_info*Datatype=&typeid(MyVariable);我如何使用它来将另一个变量类型转换为该类型?我试过这个,但它不起作用:std::cout使用类型转换的函数形式也不起作用:std::cout 最佳答案 很简单,您不能使用type_info来做到这一点。此外,在您的示例中,DataType不是类型,它是指向type_info类型对象的指针。你不能用它来转换。转换需要类型,而不是指针或对象!在C++0x中,您

c++ - 为什么我的自定义迭代器不能使用 STL 拷贝?

我为answertoanotherquestion写了一个OutputIterator.在这里:#includeusingnamespacestd;templateclassqueue_inserter{queue&qu;public:queue_inserter(queue&q):qu(q){}queue_inserteroperator++(int){return*this;}queue_inserteroperator*(){return*this;}voidoperator=(constT&val){qu.push(val);}};templatequeue_inserterm