#ifndef WINEC_H_
#define WINEC_H_
#include <iostream>
#include <string>
#include <valarray>
using namespace std;
class Pair {
private:
typedef valarray<int> arrayInt;
arrayInt years;
arrayInt bottles;
public:
Pair() : years(), bottles() {}
Pair(int A, int B) : years(A), bottles(B) {}
Pair(const int yr[], const int bot[], int i);
void Add(int i);
void show(int i) const;
};
class Wine {
private:
Pair x;
string label;
int numberYears;
public:
Wine(const char * l, int y) : label(l), numberYears(y), x(y,y) {}
Wine(const char * l, int y, const int yr[], const int bot[]) : label(l), numberYears(y), x(yr, bot, y) {}
void GetBottles();
void Show() const;
//
string & Label() const;
//int sum();
};
#endif // !WINEC_H_
#include "stdafx.h"
#include <iostream>
#include "winec.h"
using namespace std;
Pair::Pair(const int yr[], const int bot[], int i)
{
//Czooo tu zarobić ?????!!!!
}
void Pair::Add(int i)
{
for (int j = 0; j < i; j++)
{
cout << "Podaj rocznik: ";
cin >> years[j];
cout << "Podaj liczbe butelek: ";
cin >> bottles[j];
}
}
void Pair::show(int i) const
{
for (int j = 0; j < i; j++)
{
cout << "\tRocznik" << "\t" << "Butelki" << endl;
cout << "\t" << years[j] << "\t" << bottles[j] << endl;
}
}
void Wine::GetBottles()
{
cout << "Podaj dane o winie " << label << " dla " << numberYears <<" rocznikow: " << endl;
x.Add(numberYears);
}
void Wine::Show() const
{
cout << "Wino" << label << endl;
x.show(numberYears);
}
/*string & Wine::Label() const
{
return label;
}
/*int Wine::sum()
{
}*/
#include "stdafx.h"
#include <iostream>
#include "winec.h"
using namespace std;
int main()
{
/*cout << "Podaj nazwe wina: ";
char lab[50];
cin.getline(lab, 50);
cout << "Podaj liczbe rocznikow: ";
int yrs;
cin >> yrs;
Wine holding(lab, yrs);
holding.GetBottles();
holding.Show();*/
const int YRS = 3;
int y[YRS] = { 1993, 1995, 1998 };
int b[YRS] = { 48, 60, 72 };
Wine more("Gushing Grape Red", YRS, y, b);
more.Show();
//cout << "Laczna liczba butelek wina: " << more.Label() << " :";
return 0;
}
Dobra więc jak widać tworze klasę Pair zawierającą dwa obiekty valarray następnie klasa Wine zawiera obiekt klasy Pair. Chciałem utworzyć konstruktor
Wine(const char * l, int y, const int yr[], const int bot[])
czyli obiektom valarray będą przypisywane lub zastępowane lub inicjalizowane (nie wiem xD) wskaźniki tablic, problem w tym, że valarray nie ma operatora=, można zainicjalizować tablice tego typu w ten sposób: valarray<int> obiekt (yr, y) ale wyskakuje mi bład term does not evaluate to a function taking N argument.
W jaki sposób mam zbudować ten konstruktor mam użyć szablonów klas ? Bo już sam nie wiem