How to explicit instantiate template constructor in C++?

给你一囗甜甜゛ 提交于 2019-12-06 02:27:26

You're almost there, the problem is the last argument must be a reference as it's in the template declaration:

template AABB::AABB<Triangle>(const idx_t, const idx_t, const vector<Triangle>&);
//                                                                           ^^^

Also, as T.C pointed out, you can remove <Triangle> because it can be inferred from the type of the argument:

template AABB::AABB(const idx_t, const idx_t, const vector<Triangle>&);

You cannot explicitly define the type for a template constructor.
Instead, they will be defined from the arguments.

As an example, consider the following code:

struct S {
    template<typename T>
    S(T t) { }
};

// ...

S s{'c'}

Here you don't actually require to specify the type and it is defined from the argument as char.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!