# define ZY2_H_
#include
#include
#include
Typedef STD: : valarray
template
{
Private:
T1 a;
T2 b;
Public:
Pair (const T1 & amp; Aval, const T2 & amp; (aval) bval) : a, b (bval) {}
Pair () {}
T1 & amp; The first () {return a; }//return type for the T1 & amp; That can modify the data, for general object
T2 & amp; The second () {return b; }//return type for the T2 & amp; That can modify the data, for general object
T1 first const () {return a; }//return type for T1, after add const, make can't modify the data for constant object
T2 second const () {return b; }//return type for T2, after add const, make can't modify the data for constant object
Pair
};
Typedef Pair
PairArray & amp; Pair
{
If (this==& amp; P)
return *this;
A=p.a.
B=p.b.
return *this;
}
The class Wine: private STD: : string, private Pair
{
Private:
Int years;
Public:
Wine () {}
Wine (const char * l, int y, const int yr [], const int bot [])
STD: : string (l), years (y), Pair
Wine (const char * l, int y) : STD: : string (l), years (y), Pair
Void GetBottles ();
Const STD: : string & amp; Const Label () {return (const STD: : string & amp;) (* this); }
Const int the sum () {return Pair
Void the Show () the const;
};
Void Wine: : GetBottles ()
{
ArrayInt year (years);
ArrayInt bottle (years);
std::cout <"Enter" & lt; <(const STD: : string & amp;) (* this) & lt; <"The data for" & lt;
std::cout <"Enter year:";
STD: : cin & gt;> Year [I];
std::cout <"Enter bottles for that year:";
STD: : cin & gt;> Bottle [I];
}
Pair
Pair
}
Void Wine: : Show () const
{
std::cout <"Wine:" & lt; <(const STD: : string & amp;) (* this) & lt;
std::cout <"\ t" & lt;
}
}
# endif
//attach the caller
#include
# include "zy2. H"
Int main ()
{
Using STD: : cout;
Using STD: : cin;
Using STD: : endl;
Cout & lt; <"Enter the name of wine:";
Char lab [50].
Cin. Getline (lab, 50);
Cout & lt; <"Enter the number of years:";
Int yrs.
Cin & gt;> Yrs.
Wine holding (lab, yrs);
Holding. GetBottles ();
Holding the Show ();
Const int YRS=3;
Int y [YRS]={1993199, 5199, 8};
48,60,72 int [YRS] b={};
Wine more (" Gushing Grape Red ", YRS, y, b);
More. The Show ();
Cout & lt; <"Total bottles for" & lt;
}
CodePudding user response:
STD: : string (l), years (y), Pair//write PairArray (ArrayInt (yr, y), ArrayInt (bot, y)) compiler can accept,
But such writing PairArray (ArrayInt (yr, years), ArrayInt (bot, years)) compiler is not acceptable. Great god teach genuflect is begged
You stick error directly, the code for a long, looked tired,
This is in the constructor, PairArray as the parent class structure, yr, y, bot, y is the constructor parameters, so no problem,
Years for members of the subclass, the process of the structure of the c + + is to structure the parent class to subclass first, initialization list prior to the constructor of a class, in the initialization list in subclasses member to construct the superclass is wrong,