Mam mały problem. Stworzyłem klasę elementy, w której destruktor tworzy nowe zbiory(tablice dynamiczne). W mainie stworzyłem kilka, wszystko ładnie się wyświetla i mogę przypisywać wartości. Zastanawiam się teraz jak wywowłać poszczególne elementy. Np. chciałbym sprawdzić jakoś wartość ma drugi element zbioru a. Co powinienem wpisać? Miałby ktoś może pomysł gdzie i jak przechowywać ilość elementów w tych zbiorach/tablicach?
main.cpp
#include "stdafx.h"
#include <cstdlib>
#include "Elementy.h"
#include "Zbiory.h"
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Elementy<int> a(3);
Elementy<string> b(2);
Elementy<int> c(1);
Elementy<int> d(2);
system("pause");
return 0;
}
#pragma once
#include <iostream>
using namespace std;
template<class typ>class Elementy
{
protected:
typ *tab;
public:
Elementy(int=1);
~Elementy();
};
template<class typ> Elementy<typ>::Elementy(int i)
{
tab = new typ[i];
cout << "TWORZENIE NOWEGO ZBIORU!" << endl;
for (int j = 0; j < i; j++)
{
cout << "Podaj wartosc elementu zbioru nr " << j + 1 << ": ";
cin >> tab[j];
}
}
template<class typ>Elementy<typ>::~Elementy()
{
delete[] tab;
}