I should be able get these 4 files to compile without changing anything. I first thought the .t file was a header file but then it makes it a (.h) file, and i already have "arrayi.h" for that? Can anyone help me format them correctly? Please and thank you.
I have this 4 files to put in 1 project: .h / .t / .cpp / client driver.cpp.
.t below
// File name : arrayi.t
#ifndef ARRAYI_T_
#define ARRAYI_T_
#include <iostream>
#include <cstdlib>
#include <cassert>
using namespace::std;
// Default constructor for class Array
template<typename T>
Array<T>::Array(int arraySize)
{
cout << "calling the constructor \n";
}
// Overloaded output operator for class Array
template<typename T>
ostream &operator<<(ostream &output, const Array<T> &a)
{
int i;
output << "{ ";
for (i = 0; i < a.size; i++)
{
output << a.ptr[i] << ' ';
if ((i + 1) % 10 == 0)
output << "}" << endl;
} //end for
if (i % 10 != 0)
output << "}" << endl;
return output; // enables cout << x << y;
}
#endif
.h below
// File name : arrayi.h
#ifndef ARRAYI_H_
#define ARRAYI_H_
#include <iostream>
#include <cstdlib>
#include <cassert>
using namespace::std;
template<typename T> class Array;
template<typename T>
ostream &operator<< (ostream& output, const Array<T> &a);
template<typename T>
class Array
{
friend ostream &operator<< <>(ostream &output, const Array<T> &a);
public:
Array(int = 10); //constructor
private:
};
#include "arrayi.t"
#endif
.cpp below
// File name : arrayi.cpp
#include "arrayi.h"
#include "arrayi.t"
client driver.cpp below
// File name : client_driver.cpp
#include<iostream>
using namespace::std;
#include "arrayi.h"