need help with .inl and templates

I'm practicing using templates and inl files, but VS 2017
is giving me errors, what I would like is to print out the
number 23 on the main file using function templates with .inl
I tried earlier putting the implementation in the header files in another
different example and that worked but I came across code in SFML game development book that didn't have the implementation in the header and used inl file,
so I want to know how to do that

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 Mars.h/////////////////

#pragma once



template<typename T>
class Mars
{
public:
	template<typename T>
	void soof(T a);


};

Mars.inl////////////////

#pragma once



template<typename T>
void Mars::soof(T a)
{
	std::cout << a << std::endl;

};

#include "Mars.inl"

Main.cpp/////////////////////

#include <iostream>
#include "Mars.h"
#include "Mars.inl"

using namespace std;





int main()
{   
	template<typename t>
	Mars oo;
	oo.soof<int>(23);
	
}


The .inl file should be included at the end of the header file, nowhere else.

Mars.h
1
2
3
4
5
6
7
8
9
10
#pragma once

template<typename T>
class Mars
{
public:
	void soof(T a);
};

#include "Mars.inl" 

Mars.inl
1
2
3
4
5
6
7
#include <iostream>

template<typename T>
void Mars<T>::soof(T a)
{
	std::cout << a << std::endl;
}

main.cpp
1
2
3
4
5
6
7
#include "Mars.h"

int main()
{
	Mars<int> oo;
	oo.soof(23);
}
Last edited on
very good,thank you
Topic archived. No new replies allowed.