Im trying to create a struct template and a function to construct it, but when I try to use the constructor, it errors as "undefined"
Stack.h
#ifndef __STACK__
#define __STACK__
#include <iostream>
template <typename T>
struct Stack
{
size_t max_size;
T lista[];
};
template <typename T>
Stack<T> CreateStack();
#endif
Stack.cpp
#include "Stack.h"
template <typename T>
Stack<T> CreateStack()
{
T lista[10] = {};
Stack<T> stack = {10,lista};
return stack;
}
main.cpp
#include <iostream>
#include "Stack.h"
int main()
{
Stack<int> stack = CreateStack<int>();
return 0;
}
The full error is:
undefined reference to 'main.cpp:6: Stack<int> CreateStack<int>()'
But isnt it defined?
Im sorry for the for my lack of template knowlage, and thanks for any resposes!