Witam,
Mam problem z zadaniem 2 z rozdziału 14, książki S. Prata "Język C++. Szkoła Programowania" .
Chodzi o dziedziczenie prywatne szablonu klasy.
Oto plik nagłówkowy i poniżej kod programu głównego.
#ifndef WINEC_H_
#define WINEC_H_
#include <iostream>
#include <valarray>
#include <string>
#include "stdafx.h"
template <class T1, class T2>
class Pair
{
protected:
T1 Year;
T2 Bottles;
public:
T1 & first();
T2 & second();
T1 first() const
{
return Year;
}
T2 second() const
{
return Bottles;
}
Pair(const T1 & aval, const T2 & bval)
: Year(aval), Bottles(bval)
{
}
Pair() {}
};
template <class T1, class T2>
T1 & Pair<T1, T2>::first()
{
return Year;
}
template<class T1, class T2>
T2 & Pair<T1, T2>::second()
{
return Bottles;
}
template <class T1, class T2>
class Wine : private Pair<T1, T2>
{
private:
typedef std::valarray<int> ArrayInt;
typedef Pair<ArrayInt, ArrayInt> PairArray;
//PairArray <Pair::Year, Pair::Bottles>;
std::string label;
int count;
//PairArray Amount;
public:
template <class Pair>
Wine()
: PairArray()
{
}
//inicjalizuje składową label parametrem l, liczbę lat parametrem y,
//roczniki parametrem yr[], składową bottles parametrem bot[]
//template <class Pair>
Wine(const char * l, int y, const int yr[], const int bot[])
: label(l), count(y), PairArray(ArrayInt(y),ArrayInt(y))
{
for (int i = 0; i < count; i++)
{
PairArray::first()[i] = yr[i];
PairArray::second()[i] = bot[i];
}
}
//inicjalizuje składową label parametrem l, liczbę lat parametrem y,
//tworzy tablicę obiektów o długości y
//template <class Pair>
Wine(const char * l, int y)
: label(l), count(y), PairArray(ArrayInt(y), ArrayInt(y))
{
}
~Wine() {};
//metody
void GetBottles()
{
using std::cout;
using std::cin;
cout << "Podaj dane o winie \"" << label << "\" dla " << count << " rocznikow\n";
for (int i = 0; i < count; i++)
{
cout << "Podaj rocznik: ";
cin >> PairArray::first()[i];
cout << "Podaj ilosc butelek: ";
cin >> PairArray::second()[i];
}
}
const std::string & Label() const
{
return label;
}
void Show() const
{
std::cout << "Wino \"" << label << "\"\n";
std::cout.width(6);
std::cout << "Rocznik Butelki\n";
for (int i = 0; i < count; i++)
{
std::cout.width(6);
std::cout << PairArray::first()[i];
std::cout.width(7);
std::cout << PairArray::second()[i];
std::cout << std::endl;
}
}
int sum() const
{
int total = 0;
for (int i = 0; i < count; i++)
total += PairArray::second()[i];
return total;
}
};
#include "stdafx.h"
#include "winec02.h"
int main()
{
using std::cin;
using std::cout;
using std::endl;
cout << "Podaj nazwe wina: ";
char lab[50];
cin.getline(lab, 50);
cout << "Podaj liczbe rocznikow: ";
int yrs;
cin >> yrs;
Wine holding(lab, yrs); //zapisuje nazwę, liczbę roczników i przekazuje informację o
//tej liczbie do tablicy
holding.GetBottles(); //pobiera dane o roczniku i liczbie butelek
holding.Show(); //wyświetla zawartość obiektu
const int YRS = 3;
int y[YRS] = { 1993, 1995, 1998 };
int b[YRS] = { 48, 60, 72 };
//tworzy nowy obiekt, inicjalizuje za pomocą danych w tablicach y oraz b
Wine more("Gushing Grape Red", YRS, y, b);
//more.Show();
//cout << "Laczna liczba butelek wina " << more.Label() //używa metody Label()
// << ": " << more.sum() << endl; //używa metody sum()
cout << "Koniec\n";
system("PAUSE");
return 0;
}
Proszę o pomoc w znalezieniu błędów 