How does C++ link template instances

前端 未结 4 671
日久生厌
日久生厌 2020-12-01 13:05

If I define a function (maybe a class member function but not inlined) in a header file that is included by two different translation units I get a link error since that fun

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 13:42

    It actually does create multiple copies. Those copies are special and don't violate the one-definition rule. Some linkers will come along, remove the copies, and relink the functions using them; not all do.

提交回复
热议问题