I have made a header file with a templated dynamic array class that I wish to convert into secure code. The problem is that since all of the code relies on the Template I cannot put it into a static library. Any ideas how I could still make the source hidden, but keep functionality public?

There are a few options. But this is a classic problem with templated code. For instance, the STL libraries are not compiled (so basically, standard C++ libraries are open-source).

The first option is to put all the definitions of the member functions inside a .cpp file and #include the cpp file at the bottom of the header file (within the header guards). Also, you will have to put the "inline" keyword in front of the function definitions to avoid some potential multiple definition problems. Still, this method just hides the code in a separate file, but that cpp file will have to be distributed with the library as source (you cannot precompile it).

The second option is, if you know for sure all the types with which this class template can be instantiated, then you can precompile the cpp file with all the source by doing explicit instantiations in the cpp file. But, then, if anyone tries to use that library with a type that you didn't intend, it won't work (they will get an unresolved external symbol error).

Thanks, I guess it isn't possible. I just thought that maybe there could be a way to encrypt the .h file such that it can still be read directly, but I guess not.