First, radical
1.c 2.d 3.d 4.c 5.b 6.d 7.a 8.c 9.b 10.d
Second, more choice
ABC
2. ACD
3. ABD
4. AC
5. BCD
Third, judgment is wrong
1 pair
2. Wrong as you can have two member functions, int F (); and int F () const;
3. Whether the error is really inline, determined by the compiler. If the function is a recursive function, it will never be inline.
4.
5. Faults can create instances through the class of static member functions, such as single-piece mode.
6.
7. Wrong, if you can access X of the base class by inheriting a member function of the base class.
8. The wrong friend's relationship does not have delivery.
9.
10.
Fourth, write the result. The purpose is to investigate the call of the virtual function, including the other virtual function and
In the constructor, the local version of the virtual function will only be called in the destructor.
V. Write the result. Is an example of a reference count using the Handle class.
Six, answer questions
1. The focus is that any Private in the base class is not accessible in the derived class.
2. You can define a constructor in a class: a (const b &);
Or define an automatic conversion function in the class B: Operator a () const;
3. Only pure virtual functions, non-static member functions can be a constant member function.
(This question is a bit problem, the destructor can be a pure virtual function, but it cannot be a constant function)
4. There are functions INT f (void) in class A; and int F (int); overload (same name, parameter)
If you have functions INT f (void) in class A; A new implementation of INT F (Void) in the derived class B of A.
If there is virtual function Virtual int F (void) in class A; a new implementation of Virtual Int F (Void) in a derived class B,
For Override.
5. A (const a & one). When this copy construct function is called, the parameter is stack, if not use, it is necessary
Create a copy of an ONE in the stack, and this requires a copy constructor. This will form a recursive call.
With const, it also allows a constant object as a sample to construct a new object.
6. The order of calculating sub-expression is determined by the compiler, although the stack order of the parameters is fixed in the given call mode,
But the calculation order of the parameter expression is also determined by the compiler. Different compilers or different expressions of different expressions
Inconsistency.
Seven.
1. Add a full-time function
Bool Operator> (Const A & One, Const A & Two)
{
Return one.getdata ()> two.getdata ();
}
2. No. RETURN (ONE> Two? ONE: TWO); When it is not possible to assign a constant to the variable.
3. The destructive function of the three classes of the ABC is required to be virtual.
Eight. CARD class (without ENUM, only numbers can be used)
MAIN function is omission
The following will be put into. h before // enum.
Const enum suit {spade = 0, Heart, Diamond, Club};
Const enum rank {two = 0, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace}
Class Card
{
PUBLIC:
Card (INT): MID (ID), MSUIT ((ID-1) / 13), MRANK ((ID-1)% 13) {}
Bool IssameSuit (Const Card & RHS)
{RETURN ((this == & r HS)? false: msuit == rhs.msuit);
Bool Issamerank (Const Card & RHS)
{RETURN ((this == & r HS)? false: mrank == rhs.mrank);} Bool Issuit (int SUIT)
{Return msuit == Suit;}
Bool Isrank (Int Rank)
{Return MRANK == Rank;}
Private:
Static int nbackimg; // back pattern
Const int MID;
Const int msuit;
Const int mrank;
}
nine.
1) CLASS M
{
PUBLIC:
M (int V1, int V2, Int V3, INT V4): A1 (V1), A2 (V2), A3 (V3), A4 (C4) {}
Void Turn () {Int Temp = A2; A2 = A3; A3 = TEMP;
Void Trans () {
A1 = GetNextprime (A1);
A2 = GetNextPrime (A2);
A3 = GetNextprime (A3);
A4 = GetNextPrime (A4);
}
Private:
Int A1, A2, A3, A4;
}
2) (Because the design mode is not taught, the method can be used, for example,)
Class M
{
PUBLIC:
M (int V1, int V2, int V3, int V4)
: A1 (V1), A2 (V2), A3 (V3), A4 (V4), P2 (0), P3 (0) {}
M (int V1, int V2, m * pt3, int v4)
: A1 (V1), A2 (V2), A3 (0), A4 (V4), P2 (0), P3 (Pt3) {}
M (int V1, M * PT2, INT V3, INT V4)
: A1 (V1), A2 (0), A3 (V3), A4 (V4), P2 (Pt2), P3 (0) {}
M (int V1, M * PT2, M * PT3, INT V4)
: A1 (V1), A2 (0), A3 (0), A4 (V4), P2 (Pt2), P3 (PT3) {}
Void Turn ()
{
INT TEMP = A2; A2 = A3; A3 = TEMP;
M * p = p2; p2 = p3; p3 = p;
IF (p2) p2-> turn ();
IF (p3) p3-> turn ();
}
Void Trans () {
A1 = GetNextprime (A1);
IF (p2)
P2-> Trans ();
Else
A2 = GetNextPrime (A2);
IF (p3)
P3-> Trans ();
Else
A3 = GetNextprime (A3);
A4 = GetNextPrime (A4);
}
Private:
Int A1, A2, A3, A4;
M * p2;
M * p3;
}