gpt4 book ai didi

c++ - 没有 <> 的模板 bool 函数,这是什么意思?

转载 作者:搜寻专家 更新时间:2023-10-31 01:26:35 25 4
gpt4 key购买 nike

FLIF图像库定义如下:

template bool flif_decode(FileIO& io, Images &images,
callback_t callback, void *user_data, int, Images &partial_images,
flif_options &, metadata_options &, FLIF_INFO* info);

我看过模板特化,但它仍然有尖括号。这是什么意思?

最佳答案

编译器通常能够在显式模板实例化中推导出模板参数,这就是事实。

引用[t​​emp.explicit] (exmphasis mine)

If the explicit instantiation is for a function or member function, the unqualified-id in the declaration shall be either a template-id or, where all template arguments can be deduced, a template-name or operator-function-id.

标准提供了这个附带的例子:

template void sort(Array<char>&); // argument is deduced here

在您的示例中,函数声明(也是定义)如下所示:

template <typename IO>
bool flif_decode(IO& io, /*etc*/) { /*...*/}

所以当我们稍后看到这样的显式实例化时:

template bool flif_decode(FileIO& io, /*etc*/);

编译器能够推断出 FileIO 是您希望用于 typename IO 的类型

关于c++ - 没有 <> 的模板 bool 函数,这是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55094138/

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