Hey I’m having trouble figuring out how to get my template header to work. I have to get my init constructor to take in an array and reverse it. So for example if I have [1,2,3,4] it takes it in [4,3,2,1]
this is my template class:
#pragma once
#include <iostream>
using namespace std;
template<typename DATA_TYPE>
class Reverser
{
private:
// Not sure to make this DATA_TYPE* or just DATA_TYPE
DATA_TYPE Data;
public:
// Init constructor
Reverser(const DATA_TYPE& input, const int & size)
{
// This is where I'm getting my error saying it's a conversion error (int* = int), not sure
// What to make Data then in the private section.
Data = new DATA_TYPE[size];
for(int i=size-1; i>=0; i--)
Data[(size-1)-i] = input[i];
}
DATA_TYPE GetReverse(){
return Data;
}
~Reverser(){
delete[] Data;
}
};
So yea if you could tell me what I’m doing wrong that’d be great.
That’s because when you pass array to function it converts to pointer. You must use DATA_TYPE as pointer: