gpt4 book ai didi

c++ - 以下模板函数的含义?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:30:36 26 4
gpt4 key购买 nike

#define Create_Function(Type) \
template void Function( std::vector<boost::shared_ptr<Type>>&)

Create_Function(std::string);

我在遗留代码中看到了上面的代码,但不知道它的含义。它既不是常规的非专用函数定义,也不是完整的专用函数定义。

有什么想法吗?

最佳答案

它执行显式模板实例化(参见 MSDN )

Explicit instantiation lets you create an instantiation of a templated class or function without actually using it in your code. Because this is useful when you are creating library (.lib) files that use templates for distribution, uninstantiated template definitions are not put into object (.obj) files.

给定一个通用的函数模板

template<typename T>
void Function( std::vector<boost::shared_ptr<T>>&)
{
// bla bla
}

调用宏 Create_Function(std::string); 将展开为

template void Function( std::vector<boost::shared_ptr<std::string>>&);

关于c++ - 以下模板函数的含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11989061/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com