c++ - Can a template member function specialization also be an instantiation? -
this question has answer here:
i'm running issue template specialization. following builds , runs, i'm not sure should:
// template.h template <typename t> class interface{ public: void dosomething(); }; // template.cpp #include "template.h" #include <iostream> template <> void interface<int>::dosomething(){std::cout << "did something\n";} // main.cpp #include "template.h" int main(){ interface<int> instance; instance.dosomething(); return 0; }; g++ main.cpp template.cpp; ./a.out my understanding compilation units supposed have access template specializations, main.cpp not. if understand what's happening correctly, specialization in template.cpp instantiates interface< int >, symbol generated , links happily. however, i'm pretty sure falls realm of undefinedness , can't count on working everywhere. can please confirm or deny suspicions?
thanks!
Comments
Post a Comment