0

I'm trying to make a class for handling matrices, but it gives me compilation error saying undefined reference to linalg::Matrix<int, 4ull, 4ull>::eye().

Here are the files:

matrices.h

namespace linalg {
    template<typename T, size_t rows, size_t cols>
    class Matrix{
        std::array<T, rows * cols> values;
    public:
        static Matrix<T, rows, cols> eye();
    }
}

matrices.cpp

namespace linalg {
    template<typename T, size_t rows, size_t cols>
    Matrix<T, rows, cols> Matrix<T, rows, cols>::eye() {
        constexpr size_t min_size = rows < cols ? rows : cols;
        Matrix<T, rows, cols> eye;
        for (size_t i = 0; i < min_size; i++) {
            eye.values[i * rows + i] = (T) 1;
        }
        return eye;
    }
}

Cmake

cmake_minimum_required(VERSION 3.21)
project(Matrix)

set(CMAKE_CXX_STANDARD 20)

add_executable(Matrix main.cpp linalg.cpp)

I can't really figure out what am I missing.

codeling
  • 10,672
  • 4
  • 37
  • 67
btrut
  • 1

0 Answers0