stl

using structs in a STL list c++

て烟熏妆下的殇ゞ 提交于 2019-12-25 09:36:20
问题 I'm new to using c++ and I don't really know how to use the STL lists. I'm making a graph of intersections of city streets. Here's my structs/header files: global header #ifndef GLOBAL_H #define GLOBAL_H typedef struct Vertex_ vertex; typedef struct Edge_ ege; #endif vertex header #ifndef VERTEX_H #define VERTEX_H #include<list> #include "global.h" #include "edgelist.h" struct Vertex_{ int xsect; int danger; char xstreet[25]; list<Edge_> EdgeList; struct Vertex_ *next; struct Vertex_ *prev; }

what is the type of an iterator in STL?

 ̄綄美尐妖づ 提交于 2019-12-25 08:29:55
问题 Every Variable in c++ has some type like in int i , i has a type int . Similarly we have iterators in STL which we declare say something like this map<string,int>::iterator it . What is the type of the it over here ? Is it pointer type or is it a pointer type as we gerally deference iterators to fetch values associated or pointed by those itearors in case of vectors which store int or some other type.? Or the operator * is overloaded for iterators in STL ? 回答1: 24.2.1/1 [iterator.requirements

std::string values become corrupted in Qt 5 [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-25 08:14:53
问题 This question already has answers here : const reference data member bound to a temporary initializing that reference in a constructor (2 answers) Closed 3 years ago . I am trying to use the Presage text-prediction platform in a Qt5 project but keep getting errors due to std::strings being corrupted. I have this class providing string contexts for the predictive system: class SomeClass : public ParentClass { public: SomeClass(const std::string& _past_context) : past_context(_past_context) { }

Passing a third argument to sort function of C++(STL)

♀尐吖头ヾ 提交于 2019-12-25 05:58:28
问题 Normally compare function of sort in c++ takes two arguments e.g: sort(v.begin(),v.end(),compare); bool compare(int a,int b) . . . But in the vector I have stored an array and I want to sort the vector based on a particular index. viz: int arr[3]; vector<arr> v; How can I use sort function if I want to sort v based on index 0 or 1 or 2(depending on user's input)? Here problem is that when I will write compare function: bool compare(int *arr,int *arr1) then how can I tell this function to sort

Passing a third argument to sort function of C++(STL)

ε祈祈猫儿з 提交于 2019-12-25 05:57:27
问题 Normally compare function of sort in c++ takes two arguments e.g: sort(v.begin(),v.end(),compare); bool compare(int a,int b) . . . But in the vector I have stored an array and I want to sort the vector based on a particular index. viz: int arr[3]; vector<arr> v; How can I use sort function if I want to sort v based on index 0 or 1 or 2(depending on user's input)? Here problem is that when I will write compare function: bool compare(int *arr,int *arr1) then how can I tell this function to sort

Mixing STL debug/release libraries

会有一股神秘感。 提交于 2019-12-25 04:48:30
问题 I'm aware that mixing debug and release libraries that pass STL containers to each other causes big problems. But what exactly in 'debug' or 'release' causes this? I have a QT project that gets built as 'release', but it has /DEBUG added to the compiler flags. If I build another QT project under 'debug' (which also has the /DEBUG flag), are they compatible? Or is there an optimization flag or some other flag that makes them incompatible? Basically, is there a way I can look at the compilation

boost multi_index_container and slow operator++

那年仲夏 提交于 2019-12-25 04:46:20
问题 It is follow-up question for this MIC question. When adding items to the vector of reference wrappers I spend about 80% of time inside ++ operator whatever iterating approach I choose. The query works as following VersionView getVersionData(int subdeliveryGroupId, int retargetingId, const std::wstring &flightName) const { VersionView versions; for (auto i = 0; i < 3; ++i) { for (auto j = 0; j < 3; ++j) { versions.insert(m_data.get<mvKey>().equal_range(boost::make_tuple(subdeliveryGroupId + i,

C++ STL - Inserting a custom class as a mapped value

强颜欢笑 提交于 2019-12-25 04:10:24
问题 I have a class: class Monster : public Player { public: // Copy constructor - used for populating monster list in Game class Monster(int newType) { type = newType; canmove = true; notforward = false; } int type; bool operator==(const Monster& m) const {return type == m.type;} bool operator!=(const Monster& m) const {return type != m.type;} bool operator< (const Monster& m) const {return type < m.type;} bool operator<=(const Monster& m) const {return type <= m.type;} bool operator> (const

Sorting a buffer using STL SORT

若如初见. 提交于 2019-12-25 04:06:13
问题 I am trying to sort a buffer using STL sort. Now, Im using qsort but i read that stlsort has a better performance because of the inline "compare" function. The buffer has elements of size 52. It has, for example, 1024 elements of size 52. Here is a part of my code. It is working well, but I want to use the STL sort. I am sorting a fixed length file. Each fixed length file has a record size, so the user has to inform the record size. In the example below i put 52. HANDLE hInFile; char *

Undefined symbol std::__throw_bad_function_call

那年仲夏 提交于 2019-12-25 03:22:26
问题 I'm building C++ code in Eclipse CDT with g++ and I'm getting the following linker error: Undefined symbols for architecture x86_64: "std::__throw_bad_function_call()", referenced from: std::function<void (graphics::RenderingContext*)>::operator()(graphics::RenderingContext*) const in GameWindow.o I have std::function members in a class called GameWindow. Is there something I have to link to in order to get code using std::function to link properly? 回答1: Turns out my lib path wasn't set