Reputation: 3052
Example:
void foo(int a,int b=12) {
...
}
Since which version of C++ is this legal? Was it introduced in C++11?
Upvotes: 15
Views: 1561
Reputation: 50053
This is legal in all standardized versions of C++, starting with C++98.
Upvotes: 15
Reputation: 385104
Per Bjarne's "History of C++" (see page 6), default arguments were added in the very first version of the very first incarnation of C++, C With Classes, whose "spec" (if you can call it that) was published back in 1980.
They remained present through to initial standardisation in 1998, and remain present to this day.
In other words, every version of C++ since the dawn of time has supported default arguments.
In other words: literally forever. :)
Upvotes: 17
Reputation: 101
I started using C++ in 1991, and default arguments were present then in Borland C++ v3.0 and also in Stanley Lippman's book C++ Primer 2nd ed (also 1991). I imagine that qualifies as 'legal' - or it did at the time!
Upvotes: 5