I'm starting to use templates more often, and I find that explicitly putting everything together in those headers is working smoothly most of the time. However, I find that I then ruin my ability to see the simple outline of my code. I've followed some forum topics and links about potential ways to separate template declarations from template definitions, but everything I've seen so far warns me against it in some way or another. Does anyone have any good suggestions for how to separate headers of templates from the implementations and still automatically get the proper behavior without any extra maintenance? Well, actually, I guess my question is better asked as, is there a good way to keep just declarations together in class headers when templates are involved? I anticipate getting a few links that I've seen as answers, but maybe I haven't seen them. Either way, can you please give me the bottom line too if referencing other answers?
When I want to separate definitions and declarations of templates, I usually write only the declaration in the header. I put the definition in a .inl (for inline), which I include in the header.
I also use .inl for automatically generated code, e.g. lookup tables generated from static data.
I gave this a try and put the declarations in the header like usual, and then I put the definitions in the included file, which I included at the bottom of the header. This is working really well for me so far. This is exactly what I was looking for!
Thanks!
Okay,
I thought this was all worked out, but now I have some situation where I am getting duplicate symbols. I can fix it by removing the included file from the headers and just include them in source files that get complaints of missing symbols. However, I might be doing something wrong, and it seems that things have gotten very complicated before I ran into this issue. I'm wondering if there is something I should look for that might be causing the problem, or if sometimes this approach of including templated qualified member function definitions in header files is maybe not a full proof approach.
Any suggestions?