What you do is undefined behavior. However, I am going to explain why this works fine.
std::stack<T, TContainer> , , . .
, , - std::stack::value_type. std::stack::push :
void push( const value_type& value );
, :
using value_type = typename TContainer::value_type
, , , , TContainer! vector<string>::value_type, value_type string. , T, int , .
, .
, , :
undefined, T Container:: value_type. ( ++ 17)
.