template class with .inl logic

Nov 9, 2021 at 11:23am
How can I create and implement a template class with *.inl implementation in c++ using vs 2019? I also need the steps to compile it as well.
Nov 9, 2021 at 12:10pm
I am trying to create .INL file type in VS 2019, but can see only builtin C/C++ extensions. Is there any other way to create it?

I need to include template class with template implementation in .INL file.
Something like this:

//InlSampleTest.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef INLSAMPLE_TEST_H
#define INLSAMPLE_TEST_H

struct InlSampleTest {

void foo(const int& inFoo);

template <typename T>
void bar(const T& inBar);

};

#include "InlSampleTest.inl"
#endif // INLSAMPLE_TEST_H



//InlSampleTest.inl

1
2
3
4
5
6
7
8
9
10
11
12

#include "InlSampleTest.h"  //needed for intellisense sometimes

#include <iostream>
template <typename T>
void InlSampleTest::bar(const T& inBar);
{
   std::cout<< inBar << std::endl;
}







Nov 9, 2021 at 12:37pm
I am trying to create .INL file type in VS 2019, but can see only builtin C/C++ extensions.
What does 'see' mean? You need to add the .inl file to your project like any other .cpp or .h file.
Last edited on Nov 9, 2021 at 3:00pm
Nov 9, 2021 at 2:12pm
While in VS2019, after I click Add->New item, I see only the below options.
Where can I find .inl?

C++ file (.cpp)
Header file (.h)
C++ class
C++ Module interface unit (.ixx)


Nov 9, 2021 at 2:26pm
How can I create and implement a template class with *.inl implementation in c++ using vs 2019?

And

I am trying to create .INL file type in VS 2019, but can see only builtin C/C++ extensions.

Simply rename the extension. Header files by themselves aren't directly compileable so the extension is really only for us hoo-mans.

I routinely use .hpp header files instead of .h when creating C++ code. When creating a new file to add to the current project/solution I use one of the available built-in types and change the name. Including the extension.

I'm lazy enough I select the first available file type (.cpp) and change the name and extension to whatever I want before VS creates the file.

You can rename a file that is already in the project/solution list as well. The Solution Explorer view of where your project's files are sorted can be manually changed. Drag and drop.

This isn't rocket science after all.
Nov 9, 2021 at 5:58pm
Ok understood, thanks to clarify.
Topic archived. No new replies allowed.