Tuesday 17 December 2019

c++ - Templates and splitting into .h/.cpp files











I am going to create a couple of ADTs and compare their performance(I am taking a data structures course and want to experiment;note: our instructor uses Java). I want to create generic classes so that I am not stuck with a particular datatype. I read a long time ago that it is not possible to split templated classes. What is the best approach to keep the code clean? The most obvious approach is to simple uses .cpp files without hiding implementation, such as in java. Is there any other approach that I could use?



Answer



Some people use an "ipp" file that is included by the header.



Besides something like that...it is what it is. You can't put template code in a compiled file and have it available outside of it.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...