Page 1 of 1

Warum hat std::vector 2 Konstruktoren statt 1 mit Standardargument?

Posted: 16 Jan 2025, 06:02
by Guest
Ich habe mir cppreference.com angesehen und Folgendes gefunden

Code: Select all

vector();
explicit vector( const Allocator& alloc );
Warum nicht einfach

Code: Select all

explicit vector(const Allocator& alloc = Allocator());
1 Konstruktor statt 2.
Gibt es einen Grund dafür? Gleiches gilt für resize(std::size_t,const T& t) und

Code: Select all

resize(std::size_t)
Warum nicht einfach resize(std::size_t,const T& t = T())