Hello.


Here is the class that stores information about the military: Name and Age.

class Military { private: char FIO; int Age; public: Military(char FIOName, int A):FIO(FIOName),Age(A){}; Military(){}; ~Military(){}; char get_FIO(){return FIO;}; int get_Age(){return Age;}; void set_F(char FIOName){FIO=FIOName;}; void set_Age(int A){Age=A;}; 

His descendant - Private: (year of service, branch of service + name and age from the parent class Military )

 class Soldier: public Military { private: int YearOfServ; char TypeOfForces; //Π³ΠΎΠ΄ слуТб. Ρ€ΠΎΠ΄ войск public: Soldier(int YOS, char TOF, char FIOName, int A): Military(FIOName),Military(A),YearOfServ(YOS),TypeOfForces(TOF){}; Soldier(){}; ~Soldier(){}; int get_YearOfServ(){return YearOfServ;}; char get_TypeOfForces(){return TypeOfForces;}; void set_YearOfServ(int YOS){YearOfServ=YOS;}; void set_TypeOfForces(char TOF){TypeOfForces=TOF;}; } 

When I try to compile, I get the error: Could not find a match for 'Military :: Military (char)'
in line

 Military(FIOName),Military(A),YearOfServ(YOS),TypeOfForces(TOF){}; 

And in it is the same error Base class 'Military' is initialized more than once


And everything would be fine, having given an example from the training manual, it works perfectly, although everything is still there, just not military, but geometric figures.


Parent:

  class Figure {private: int Color;//ΠΏΠΎΠ»Π΅ класса, доступноС Ρ‚ΠΎΠ»ΡŒΠΊΠΎ классу public://ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ класса, доступныС классам-ΠΏΠΎΡ‚ΠΎΠΌΠΊΠ°ΠΌ ΠΈ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ΅ Figure(int PC):Color(PC){}; Figure(){}; ~Figure(){}; int get_Color(){return Color;}; void set_Color(int PC){Color=PC;}; virtual AnsiString Info() {AnsiString res; switch (Color) { case 1:res="красный"; break; case 2:res="ΠΎΡ€Π°Π½ΠΆΠ΅Π²Ρ‹ΠΉ"; break; case 3:res="ΠΆΠ΅Π»Ρ‚Ρ‹ΠΉ";break; case 4:res="Π·Π΅Π»Π΅Π½Ρ‹ΠΉ"; break; case 5:res="Π³ΠΎΠ»ΡƒΠ±ΠΎΠΉ"; break; case 6:res="синий"; break; case 7:res="Ρ„ΠΈΠΎΠ»Π΅Ρ‚ΠΎΠ²Ρ‹ΠΉ"; break; };return res;}; 

Descendant: (Circle, where X, Y-coordinates of the center, R - radius)

 class Circle: public Figure {private: int X,Y,R; public: Circle(int PX,int PY,int PR,int PC): Figure(PC),X(PX),Y(PY),R(PR){} Circle(){} int get_X(){return X;} int get_Y(){return Y;} int get_R(){return R;} void set_X(int PX){X=PX;}; void set_Y(int PY){Y=PY;}; void set_R(int PR){R=PR;}; } 

In line

 Circle(int PX,int PY,int PR,int PC):Figure(PC),X(PX),Y(PY),R(PR){} 

Similarly, there is an appeal to the RS parameter which determines the color, by specifying the class to which this parameter belongs. Figure (PC) And there are no such errors as I do.

  • one
    In the Military class, you have defined a constructor with no parameters and a constructor with the 2nd one (char and int), and you call a constructor with one char parameter that is not defined - _perchuk
  • Thank you so much) - BlackOverlord
  • one
    Yes, or define such a Military (char FIOName): FIO (FIOName) {}; - _perchuk

2 answers 2

In the Military class, you have defined a constructor with no parameters and a constructor with the 2nd one (char and int), and in the descendant you call the constructor with one char parameter, which is not defined.

You must either call the Soldier Military(FIO, A) or define the Military(char FIOName):FIO(FIOName){} .

    Not char , but char *, everywhere.

    • Cannot convert 'AnsiString' to 'char *' I put AnsiString everywhere) - BlackOverlord
    • It is not always good. You have to add ".c_str ()" for functions where exactly char * is required. For example, Application-> MessageBoxA (...) and for I / O. - BuilderC