Good day all,
I'm trying to create a template class just for learning purposes. And i keep coming up with two errors... Here's the script:
HEADER FILE "lottoclass.h"
#ifndef LOTTOCLASS_H_INCLUDED
#define LOTTOCLASS_H_INCLUDED
using namespace std;
template<typename T>
class Lottery
{
public:
Lottery();
~Lottery();
T Resize(T* array, int i);
void addVar(int b, T b2);
private:
T* array2;
int arraySize;
}
template<typename T>
Lottery<T>Lottery()
{
array2=0;
arraySize=0;
}
template<typename T>
T Lottery<T>::Resize(T* array, int i)
{
T* arr3= new T [i];
delete[] array;
return array3;
}
template<typename T>
Lottery<T>::~Lottery()
{
delete[] array2;
array2=0;
}
template<typename T>
void Lottery<T>::addVar(int b, T b2)
{
array2[b]= b2;
}
And here's the int main();
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "numonly.h"
#include <string>
#include "LottoClass.h"
int main()
{
//Setting up variables//
string n;
int n1, b2;
cout<<"Welcome to R-Lot!"<< endl;
//Continue a loop until user inserts correct answer//
while (true)
{
cout<<"R-Lot for Numbers (1) or Names (2)";
n1=stringtonumber(EnterOnlyNumbers());
if (n1 == 1 || n1 == 2)
break;
}
if (n1 == 1)
{
int i, i2;
i=i2=0;
cout<<"How many units?";
b2=stringtonumber(EnterOnlyNumbers());
Lottery<int>Lotto();
Lotto.Resize(array2, b2);
while (i<b2)
{
cout<<"What will [ " <<i<<" ] be? ";
i2=stringtonumber(EnterOnlyNumbers());
Lotto.addVar(i,i2)
cout<<"[ "<<i<<" ] = "<<i2<<endl;
i++;
}
}
return 0;
}
Ok, first error is in the main(), when the compiler runs Lotto.Resize(array2, b2); it says:
error: request for member 'Resize' in 'Lotto', which of non-class type 'Lottery<int>()'
error: 'array2' was not declared in this scope
error: request for member 'addVar' in 'Lotto', which of non-class type 'Lottery<int>()'
Can someone please help me resolve these errors... Array2 is clearly defined as a private variable, and in the constructor...
Thanks alot