Я смогу собрать эти 4 файла без каких-либо изменений. Сначала я подумал, что файл .t - это заголовочный файл, но затем он становится файлом (.h), и у меня уже есть «arrayi.h» для этого? Может кто-нибудь помочь мне правильно их отформатировать? Пожалуйста и спасибо.
У меня есть 4 файла для размещения в 1 проекте: .h / .t /. cpp / клиентский драйвер. cpp.
.t ниже
// 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 ниже
// 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 ниже
// File name : arrayi.cpp
#include "arrayi.h"
#include "arrayi.t"
драйвер клиента. cpp ниже
// File name : client_driver.cpp
#include<iostream>
using namespace::std;
#include "arrayi.h"