First, you must understand that the body of the constructor is intended only to run code to complete the initialization of your object as a whole; members must be fully initialized before entering the body.
Ergo, all members are initialized in the (implicit, if not explicit) initialization list. Obviously, const variables must be initialized in the list, because as soon as you enter the body, they are already supposed to be initialized; you are just trying to assign them.
Typically, you do not have const members. If you want these members to be unchanged, just do not give them public access that could change them. (In addition, the presence of const members makes your class unassignable, as a rule, unnecessarily.) Going along this route easily eliminates your problem, because you simply assigned them values ββin the constructor body as you wish.
The method you want to do while maintaining const can be:
class ImageBase { public: const int width, height; protected: ImageBase(const MetaData& md) : width(md.width()), height(md.height()) {}
I do not think this route is worth it.
GManNickG
source share