Get the last element from a std::vector
06:23 24 Jan 2022

In the following example, I would like to get an element from my vector. But I don't understand the error:

#include 
#include 


using namespace std;

class Foo{
    virtual int end() = 0;
};

class Bar : public Foo{
    int end(){
        return 0;
    }
};


int main(){
    vector> a;
    a.push_back(make_shared());
    shared_ptr b = a.pop_back();
}

Here the error:

 g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:21:35: error: conversion from ‘void’ to non-scalar type ‘std::shared_ptr’ requested
   21 |     shared_ptr b = a.pop_back();
      |                         ~~~~~~~~~~^~
c++ shared-ptr