How can I initialize an array, s
of template type T
in my constructor Stack()
? This might be a really simple question, but I don't know much of c++. I get this error when compiling (GNU GCC):
error: incompatible types in assignment of 'double*' to 'double [0]'
This is how I'm initializing the Stack
object in my main.cpp
:
Stack<double> stack;
And here is my Stack.h
file (the implementation is included):
#pragma once
#include <iostream>
using namespace std;
template <class T>
class Stack
{
public:
Stack();
private:
T s[];
int N;
};
template <class T>
Stack<T>::Stack() {
s = new T[5];
}