> So can you write to it?
Just as there can be intrinsic state, extrinsic state, shared state, computed state,
there can also be mutable state and immutable state.
1 2 3 4 5 6 7 8
|
struct person
{
// ...
const std::string name ; // intrinsic, immutable state.
int age_in_years() const ; // computed, immutable state
private:const std::tm time_of_birth ;
// ...
};
|
If your notion of state is limited to 'something that can be written into', you have a very long way to travel.
> What if at one point it becomes desirable for Player to share state or code with other namespaces?
You need to read up on namespace composition; and while you are at it you might as well also learn about namespace selection, intelligently combining composition with selection, and namespace versioning.
Recommended: Chapter 14 of Stroustrup's 'The C++ Programming Language (Fourth Edition)'
It is only about thirty pages or so, and well worth careful study.
> Or if you want to support different subtypes of a Player?
Right.
And what if you want to implement many different kinds of sorts (which to you would necessarily have to be different subtypes of std::sort)? And the only way that you can think of doing it by trying to implement inheritance on top of the namespace std?
If you need a hierarchical arrangement of different player types, if you need a type player which has overloaded operators, if you can't live without taking the memory address of the player ... and so on and so forth ...
In short, if you need an instance of an object of the type player, a class is required.
So, your (extremely valid, I may add) proposition is: if a class is required, then a class is required.
What else is new?