jeudi 28 février 2019

How to use templates while separating header and implementation files?

I'm trying to implement a Template while separating the Header and Implementation file.

I'm getting this error when building the project:

error C2955: 'Series': use of class template requires template argument list

Header.h

#ifndef SERIES_H
#define SERIES

template <class T>
class Series {
    private:
        T var;

    public:
        Series(T v);
    };

#endif

Implementation.cpp

#include <iostream>
#include "Header.h"

template <class T>
Series::Series(T v) {
    var = v;
    std::cout << var;
}

Main.cpp

#include <iostream>
#include "Header.h"

int main() {
    Series<int> w(10);
}

The project builds successfully when everything is in one file

What do I need to do to make this work?

Aucun commentaire:

Enregistrer un commentaire