Hello. Trying to decipher the home, stalled (

Here is the task:

Create a base class - a car that must contain data elements: the number of wheels and engine power, as well as a virtual function that issues this data to the console.

Create derived classes - bus and truck, containing data: number of passengers for the bus, load capacity for the truck. Override the inherited function so that in derived classes it displays all data about objects. All classes must be in orthodox canonical form.

Create a function that outputs data about the object to the console, without having any information about which class the input parameter is.

Decipher what this inherited function should do? Is this a virtual function? How did I get out ... Am I slowing down ... (What kind of canonical orthodox ... what is this !? And how can I create the last ?? I will enter 180, and the class has a private value = 180 ... derive it, so ?? Generally confused ...

It seems to have written the main inheritance - not difficult, I am familiar with these matters ...

    2 answers 2

    Googled to the phrase "orthodox canonical form."

    This got out: http://opensource.com.ua/contents/978546900189p.html .

    Specific data types should be distinguished from the class implementations described in the previous chapter. Specific types work according to the same predictable rules as the built-in C types (say, int). They are created on a special model in which members of classes of specific data types transmit information to the C ++ compiler type support system. This allows the compiler to generate efficient and reliable code for abstractions of arbitrary complexity. We will call this form the orthodox canonical form of the class. The term "canonical" means that the form defines a system of rules that must be followed by the compiler when generating code, and "orthodox" means that the form is directly supported by the language itself. [...]

    On the "Orthodox Canonical Form" there was a more human explanation :

    The Orthodox Canonical Class Form

    • The default constructor is used.
    • A copy constructor: used in the call-by-value parameters.
    • An assignment operator
    • A destructor: Invoked when an object is deleted.

    In general, they want a regular constructor, a copy constructor, an assignment operator, and a destructor. Something like this.

    • Plus for the "Orthodox" canonical form. - gecube

    Yes, the display function must be virtual. In derived classes, you redefine it according to the condition of the problem. A function that does not have information about the type of an object is obviously external to the classes and accepts a pointer to the base class and simply calls the member function responsible for displaying the parameters of the particular class. Polymorphism in action. Because Since this f-tion member is virtual, then by passing the pointer to the base or derived classes as an argument, the corresponding functions of the corresponding classes will be called. If the function would be non-virtual, then a member function of the base class would be called - do not go to the grandmother.

    Regarding the orthodox canonical record - I can not help. I can hardly imagine what they had in mind. I can suggest class member functions not to be built in, but to spread the declaration and definition.