error C1075: end of file found before the left brace '{'

//Header file section
#include<iostream>
using namespace std;

template <class T>
class SimpleVector
{
private:
T *aptr; //To point to the allocated array
int arraySize; //Number of elements in the array
void memError(); //Handles memory allocation erro
void subError(); //Handles subcripts out of range

public:
//Default constructor
SimpleVector()
{
aptr = 0; arraySize = 0;
}

//Constructor declaration
SimpleVector(int);

//Copy constructor declaration
SimpleVector(const SimpleVector &);

//Destructor declaration
~SimpleVector();

//Accessor to return the array size
int size() const
{
return arraySize;
}

//Accessor to return a specific element
T getElementAt(int position);

//Overload [] operator declaration
T &operator[](const int &);
};

//**************************************************************
// Constructor for SimpleVector class. Sets the size of the *
// array and allocates memory for it. *
//**************************************************************

template <class T>
SimpleVector<T>::SimpleVector(int s)
{
arraySize = s;
//Allocate memory for the array.
try
{
aptr = new T[s];
}
catch (bad_alloc)
{
memError();
}

// Initialize the array.
for (int count = 0; count < arraySize; count++)
*(aptr + count) = 0;
}

//******************************************
//Copy constructor for SimpleVector class. *
//******************************************

template <class T>
SimpleVector<T>::SimpleVector(const SimpleVector &obj)
{
//copy the arraysize.
arraySize = obj.arraySize;

//Allocate memory for the array.
aptr = new T[arraySize];
if (aptr == 0)
memError();

//Copy the element of obj's array.
for (int count = 0; count < arraySize; count++)
*(aptr + count) = *(obj.aptr + count);
}

//************************************
//Destructor for SimpleVector class. *
//************************************

template<class T>
SimpleVector<T>::~SimpleVector()
{
if (arraySize > 0)
delete[] aptr;


//******************************************************
//memError function. Display an error message and *
//terminates the program when memory allocation fails. *
//******************************************************

template<class T>
void SimpleVector<T>::memError()
{
cout << "Error: cannot allocate memory. \n";
exit(EXIT_FAILURE);
}

//*********************************************************
//subError function. Display an error message and *
//terminate the program when a subscript is out of range *
//*********************************************************

template<class T>
void SimpleVector<T>::subError()
{
cout << "Error: subscript out of range. \n";
exit(EXIT_FAILURE);
}

//*********************************************************
//getElementAt function. The argument is a subscript. *
// This function return the value stores at the sub- *
//cript in the array. *
//*********************************************************

template<class T>
T SimpleVector<T>::getElementAt(int sub)
{
if (sub < 0 || sub >= arraySize)
subError();
return aptr[sub];
}

//******************************************************
//overloaded[] operator. THe argument is a subscript. *
//This fnction returns a reference to the element *
// in the array indexed by the subscript. *
//******************************************************

template <class T>
T &SimpleVector<T>::operator[](const int &sub)
{
if (sub < 0 || sub >= arraySize)
subError();
return aptr[sub];
}
template<class T>
class SearchableVector : public SimpleVector<T>
{
public:
//Default constructor
SearchableVector(): SimpleVector<T>()
{}

//Constructor
SearchableVector(int size) : SimpleVector<T>(size)
{}

//copy constructor
SearchableVector(const SearchableVector &);

//Accessor to find an item
void SortItems();
};

//***************************
//Copy constructor *
//***************************

template<class T>
SearchableVector<T>::SearchableVector(const
SearchableVector &obj) :
SimpleVector<T>(obj.size())
{
for (int count = 0; count < this->(); count++)
this-> operator[] (count) = obj[count];
}
template<class T>
void SearchableVector<T>::SortItems()
{
for (int i = 0; i <= this->size(); i++)
{
for (int j = 0;j < this->size() - 1; j++)
{
if (getElementAt(j)> getElementAt(j + 1))
{
T temp = this->operator [](j);
this->operator [](j)=this->operator[](j + 1);
this->operator [](j+1=temp);

int main()

{
const int SIZE = 10; //Number of elements
int count; //loop counter

//create two SearchableVector objects.
SearchableVector<int> intTable(SIZE);
SearchableVector<double> doubleTable(SIZE);

//Inputting elements to intTable
cout << "Enter elements: " << endl;
for (count = 0; count < SIZE; count++)
{
cin >> intTable[count];
}

//Inputting elements to doubleTable
cout << "Enter elements" << endl;
for (count = 0; count < SIZE; count++)
{
cin >> doubleTable[count];
}

//Display the value in the objects.
cout << "These values are in intTable: \n";
for (count = 0; count < SIZE; count++)
cout << intTable[count] << " ";
cout << endl << endl;
cout << " These values are in doubleTable: \n";
for (count = 0; count < SIZE; count++)
cout << doubleTable[count] << " ";
cout << endl;

//Function calls to sort list of elements in tables
intTable.SortItems();
doubleTable.SortItems();

//outputtind list
cout << "After sorting int list" << endl;
for (count = 0; count < SIZE; count++)
cout << intTable[count] << " ";
cout << endl << endl;

cout << "After sorting in doubleTable: \n";
for (count = 0; count < SIZE; count++)
cout << doubleTable[count] << " ";
cout << endl;

//To pause system for a while
system("pause");
return 0;
}
//end mai
You're missing some closing }.

If you can edit your post, highlight the code portion, then click the <> button in the Format palette at the right side of the post, that'll format your code and make it much easier to read :)

1
2
3
4
5
6
7
8
9
10
11
12
//************************************
//Destructor for SimpleVector class. *
//************************************

template<class T>
SimpleVector<T>::~SimpleVector()
{
if (arraySize > 0)
delete[] aptr;


//****************************************************** 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
template<class T>
void SearchableVector<T>::SortItems()
{
for (int i = 0; i <= this->size(); i++)
{
for (int j = 0;j < this->size() - 1; j++)
{
if (getElementAt(j)> getElementAt(j + 1))
{
T temp = this->operator [](j);
this->operator [](j)=this->operator[](j + 1);
this->operator [](j+1=temp);

int main()
Topic archived. No new replies allowed.