如果标头位于预编译标头 xcode 中,则找不到默认模板参数
Default template parameter not found if header is in precompiled header xcode
>我在test.h标头中有这样的简单函数
template <class Dst = std::string, class T>
Dst format(const T&);
template <class Dst, Class T>
Dst format(const T&)
{
return Dst();
}
测试中.cpp
#include "stdafx.h"
#include "test.h"
#include <iostream>
int main(int argc , char** argv)
{
std::string f = format("");
std::cout << f;
return 0;
}
如果将此标头添加到 Xcode 中的预编译标头中
代码不再编译。
我收到"没有匹配的函数调用"错误。
如果我手动将默认参数添加到函数调用中
format<std::string>();
然后它起作用了。
如果不是声明和定义,我只留下定义......它编译。
据我了解,如果标头包含模板,则无法对其进行预编译,因为编译器仅在发现使用具有其他来源的具体类型的函数时,才从模板创建函数。没有具体类型 - 没有功能。
似乎
如果我将默认参数放在定义中而不是声明中,它似乎可以工作
template <class Dst , class T>
Dst format(const T&);
template <class Dst = std::string, Class T>
Dst format(const T&)
{
return Dst();
}
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 找不到QtResource文件中的文件
- VC++本机单元测试,找不到调试符号
- RegGetValue在当前用户下找不到名称
- 带有 -stdlib=libc++ 的 clang++ 9.0.1 找不到<optional>
- c++找不到具有相同哈希的无序集合元素
- 找不到以下加速库:boost_fiber
- 找不到 FLTK(缺少:FLTK_INCLUDE_DIR)
- 错误:当我从"WinDbg"打开可执行文件时,找不到符号文件。默认导出 ntdll 的符号.dll
- Linux上的clangd找不到默认标头
- 如果标头位于预编译标头 xcode 中,则找不到默认模板参数
- [Microsoft] [ODBC驱动程序管理器]找不到数据源名称,也没有指定默认的驱动程序
- 找不到默认构造函数
- 找不到C++默认构造函数
- 找不到默认值时生成默认值
- 找不到默认构造函数来初始化 CPP 中的成员