Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make closed source for the library written with template in C++

Tags:

c++

templates

After reading this article Storing C++ template function definitions in a .CPP file, I know that the definition of a class that uses template has to be written in the header file in some way. So a client user can use it by importing the header files. Doesn't this mean the complete implementation details are revealed to the user? Does this also mean a library written with template must be provided in an open-source way?

Thanks for helping clarify it.

like image 497
WawaBrother Avatar asked Dec 13 '22 15:12

WawaBrother


1 Answers

  1. The details of the template implementation will be visible. You can provide explicit template instantiations if you know which parameters will be necessary, however. But to be a generic solution, you have to provide the implementation so it can be used with other parameters.

  2. No, you don't have to release it as open source. Just because someone can see the code, doesn't mean it has to be open source. You can license it almost however you want, and the purchaser has to abide by those rules. After all, just because we can see the entire text of a novel doesn't mean we can do whatever we want with it.

like image 160
dappawit Avatar answered May 24 '23 01:05

dappawit