'C++ programming struct vector with multiple arguments and params as member [closed]
Trying to create a struct that has a vector as a member, but unable to make it work if vector has multiple args.
Any ideas?
struct node {
int id;
std::string name;
bool visited;
int state;
std::vector <std::string, int> edges;
};
I'd like the vector to be of this type; std::vector <std::string, int> string and int.
This is the error:
/usr/local/Cellar/gcc/11.3.0/include/c++/11/bits/stl_vector.h:477:20: error: '_M_get_Tp_allocator' has not been declared in 'std::vector<std::__cxx11::basic_string<char>, int>::_Base'
477 | using _Base::_M_get_Tp_allocator;
Solution 1:[1]
std::vector holds a sequence of a single type.
e.g. std::vector<int> v_int holds a sequence of only integers.
There are types that can themselves hold multiple types. For example, a std::pair<std::string, int> holds both a string and an int.
It is possible to have a vector of pairs, if that is what you are trying to do.
std::vector<std::pair<std::string, int>> edges;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Increasingly Idiotic |
