Creating a template class object using a template constructor

前端 未结 3 1339
[愿得一人]
[愿得一人] 2021-02-09 18:45

I\'m having trouble creating a class object from a template class in which I need the constructor to also be a template and accept a parameter when the object is created. Howev

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-09 19:21

    Solution: You can't separate template implementations from the header file. Simply don't use a cpp file and put the definition in your header file (.h file).

    Why? This is because cpp files can become precompiled sources, while templates are compile-time objects; therefore, the compiler cannot decide what type to use unless specified. So just put all your template undefined implementations in your header .h file.

提交回复
热议问题