#include <iostream>
using namespace std;
template <class T, int size>
class StaticArray_BASE
{
private:
T m_array[size];
public:
T * getArray() { return m_array; }
T& operator[](int index)
{
return m_array[index];
}
void print()
{
for (int count = 0; count < size; ++count)
std::cout << (*this)[count] << " ";
std::cout << "\n";
}
};
// member function에 대해 특수화하는것은 쉽지않다. 클래스 상속을 이용해보자.
template<typename T, int size>
class StaticArray : public StaticArray_BASE<T, size>
{};
template<int size>
class StaticArray<char, size> : public StaticArray_BASE<char, size>
{
public:
void print()
{
for (int count = 0; count < size; ++count)
std::cout << (*this)[count];
std::cout << "\n";
}
};
//char에 대해서 특수화
//template <int size>
//void print(StaticArray<char, size> &array)
//{
// for (int count = 0; count < size; ++count)
// std::cout << array[count];
// std::cout << "\n";
//}
int main()
{
StaticArray<int, 4> int4;
int4[0] = 1;
int4[1] = 2;
int4[2] = 3;
int4[3] = 4;
int4.print();
StaticArray<char, 14> char14;
char14[0] = 'H';
char14[1] = 'e';
strcpy_s(char14.getArray(), 14, "Hello, World"); // 문자를 출력할 때도 한칸씩 띄어서 출력하므로 보기 좋지 않다. -> char에 대해 특수화
char14.print();
return 0;
}