Zacariaz wrote:1. class King should be and exact copy of class Piece as it contain nothing more than the constructor call. Is this correct?
Yes.
As an aside, any class from which you intend to inherit and which sports a constructor should contain a destructor declared as virtual, i.e.
virtual ~Piece() {}. The explanation is a bit involved, just get into the habit for now.
2. I have tried different ways of writing class King's constructor, as it should be inherited automaticly (or so i thought) from the base class. This was seems to be the only thing that works. I have a hard time accepting that the constructor cant just be inherited.
Only the default constructor can "just be inherited" (if even that much, haven't tried it).
You told the compiler that Piece can
only be constructed in the way you specified. Since every King object contains a Piece object, you have to tell the compiler in the King constructor how to construct that Piece object first.
3. Is there anyway to prevent other "users" of class Piece than class King?
You could keep the Piece header away from the public, but that isn't "secure" either, and for an "insecure" solution it should suffice to add a comment to the Piece header not to inherit from it.
4. other comments and stuff are welcome as usual, but im not interested in a long discusion, i just want to know if i got it right.
As nice as it is to see you have found an interesting project to test your C++ skills on, this is the umpteenth topic on this board about poker cards. Perhaps a single topic "Zacariaz' C++ Q&A" would be better.
And your examples could be a bit more... examplish. You know, class Base and class Child, no bitfields or program logic that has nothing to do with the subject. This is not due to a dislike towards poker, it just helps communication. It keeps people focussed on what you want to know, and usually helps
you understanding the
question better even
before you post.
Oh, and your coding style is a bit hard to read. Most of the C++ code out there uses 4 space indents, spaces after ( and , as well as in front of ), and lists data members
last in a class declaration. But that's only style, i.e. in the eyes of the beholder.
And while I'm nagging at banalities, another useful habit is to place the "const" always
after the thing you're declaring const. In some places, you
cannot put "const" first, and by putting it
always last makes it more consistent.