enum class color{red,green, blue}; there is such an enum, I want to put it in a vector, and then return from the function
vector<color> getVectorFunc(); I do not understand how to do this?
vector<color> getVectorFunc(){ return //......//; } I do not understand where the problem is ?
#include <vector> enum class color {red,green, blue}; std::vector<color> getVectorFunc() { std::vector<color> v {color::red,color::green, color::blue}; return v; } int main() { std::vector<color> v = getVectorFunc(); } This is how you can put enum in a std :: vector container and return it from a function . Just do not forget to connect the vector library.
enum color { red, green, blue }; // объявление перечисления std::vector <color> getVectorFunc() // ф-я { std::vector <color> Vec; // создаём вектор принимающий enum color c; // создаём объект Vec.push_back(c); // метод push.back() добавляет переданный объект в конец вектора return Vec; // возвращаем вектор } int main() { std::vector <color> getVectorFunc(); // вызов ф-ии возвращающей enum return 0; } And what was the problem?
std::vector <color> getVectorFunc(); // вызов ф-ии возвращающей enum std::vector <color> getVectorFunc(); // вызов ф-ии возвращающей enum Yeah, how is it :) - HolyBlackCatmain . - AnTSource: https://ru.stackoverflow.com/questions/923451/
All Articles
int? Alternatively,return {color::red, color::green, color::blue};. - HolyBlackCatstd::vector<color> my_vec = getVectorFunc();. - HolyBlackCatreturn- that's all. What's the question? - AnT