1

I'm having a problem with declaring an instance of class. The code:

//main.cpp
#include "klass.hpp"

int main(int argc, char** argv)
{    
   Klass<Type::Big>* klass = new Klass<Type::Big>();
}

//klass.hpp
#pragma once

enum class Type
{
Big,
Medium,
Small,
};

template<Type T>
class Klass
{
private:
public:
Klass(/* args */);
~Klass();
};

//klass.cpp
#include "klass.hpp"

#include <iostream>

template<Type T>
Klass<T>::Klass(/* args */)
{
   std::cout << "Hello from Klass class";
}

template<Type T>
Klass<T>::~Klass()
{ 

}

I'm trying to compile with:

g++ -std=c++17 -o test.exe .\main.cpp .\klass.cpp

And I'm getting the error:

undefined reference to `Klass<(Type)0>::Klass()' collect2.exe: error: ld returned 1 exit status

Roar RaizZer
  • 197
  • 1
  • 7

0 Answers0