Why is there undefined reference?

Hello, I have the following project structure:
main.cpp
Foo.hpp
Foo.cpp


Foo.hpp:
#pragma once

template<typename T>
class Foo
{
private:
 int size;
public:
Foo();
};


Foo.cpp:
#include "Foo.hpp"

template<typename T>
Foo<T>::Foo()
{
 this->size = 0;
}


main.cpp:
#include "Foo.hpp"

int main()
{
 Foo<int> foo;

 return 0;
}


Compile with the following command:
g++ Foo.cpp main.cpp
The compiler gives:
/usr/bin/ld: /tmp/cc35sAwy.o: in function `main':
main.cpp:(.text+0x1f): undefined reference to `Foo::Foo()'
collect2: error: ld returned 1 exit status


Why is this happening?
April 4th 20 at 00:44
1 answer
April 4th 20 at 00:46
Solution
Implementation of methods of template classes must be in the header file.
Thank you - claud22 commented on April 4th 20 at 00:49

Find more questions by tags C++