I think they are pretty much equivalent in terms of run-time evaluation. There's no such thing as a virtual constructor so they pretty much amount to plain old function calls.
However,
As soon as you create a constructor, C++ stops treating your struct as a C-style Plain Old Data struct and treats it as a C++ style class.
So with the ShirleyEllis(boBirley, ...); constructor created, you could no longer write:
ShirleyEllis shirley;
Without generating a compiler error. So now instead of just writing the one function you wanted, you now need to create a default constructor.
The advantage to having a constructor is that you can initialize private/protected members (which Casey is actively avoiding) as well as call superclass constructors (which Casey is also avoiding).
Using a constructor in a C-style programming scenario is a net loss.
Here's a small code snippet to demonstrate the problem.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | struct POD {
int word;
};
struct Constructed {
Constructed(int word) {/*logic...*/}
int word;
};
int main() {
POD pod; // Uninitialized.
Constructed constructed(3); // Works fine. Initialized
Constructed compiler_error; // Nope. Either delete your constructor or create a default constructor.
}
|
EDIT:
A corollary to no longer being able to declare Constructed without a default constructor, is that you also can't declare arrays.
| POD pod_array[8]; // Valid
Constructed compiler_error_array[8]; // Invalid
|