0

I've been getting frustrated with not knowing why this happen so basically my header file doesnt want to get my function definitions from my cpp file.

I know the functions work cause I can add them to my header file itself and it works fine but it just wont work from my cpp.

main.cpp:

 #include "header.h"

using namespace std;

int main()
{
    StackType<int> myStack;
    

    return 0;
}

header.cpp

#include "header.h"

using namespace std;
template<class Type>
StackType<Type>::StackType() {}

header.h

using namespace std;

template<class Type>
class StackType
{
public:

    StackType();

}

undefined reference to `StackType::StackType()'|

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • 1
    In `header.h`, missing a `;` to complete the class declaration. – Paul T. Sep 19 '20 at 13:15
  • 1
    For completeness, it's also considered a bad idea to put [`using namespace std;` in a header](https://stackoverflow.com/q/5849457/212858). – Useless Sep 19 '20 at 13:19
  • @PaulT. , sorry that was meant to already be in the question (this is not the issue) was just trying to type out my problem and forgot the ; in the code above. also as I've stated the problem doesnt lie in my header file itself since if I add the class definition in the header file then it works fine but it doenst seem to link the function to the definition in my cpp. – Lourens Malan Sep 20 '20 at 18:58

0 Answers0