I'm trying to make a vector with the class type MyClass. Why do the functions v.size () and v.capacity () work fine, and v.pop_back () and v.front () don't work? It does not display anything after running the program.

class MyClass { public: MyClass(int x = 1) : xp(x) {} int x() const { return xp; } private: int xp; }; int main() { setlocale(LC_ALL, "Russian"); vector<MyClass> v {7, 9, 8}; cout << "\n\tВектор с пользовательским типом данных"; cout << "\n\tСодержимое вектора: "; for (const auto& f : v) { cout << fx() << std::endl; } cout << "\tsize(): " << v.size() << endl; cout << "\tcapacity(): " << v.capacity() << endl; cout << "\n\tЭлемент с индексом 1 - > " << endl; v.pop_back(); cout << "\n\tПервый элемент в векторе: " << endl; v.front(); } 

    2 answers 2

    The pop_back function deletes an element silently and returns nothing. And the front function returns a reference to the first element. Style C: there is no request to print something, I will not.

      Like that:

       cout << "\n\tЭлемент с индексом 1 - > " << v[1] << endl; cout << "\n\tПервый элемент в векторе: " << v.front() << endl;