我有這樣一個簡單的函數在一個test.h頭默認模板參數,如果標題是預編譯的頭的xcode
template <class Dst = std::string, class T>
Dst format(const T&);
template <class Dst, Class T>
Dst format(const T&)
{
return Dst();
}
在TEST.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>();
然後它工作。
如果不是一個聲明和一個定義,我只留下定義......它編譯。
請嘗試創建一個[最小,完整,可驗證的示例](HTTP://計算器。 com/help/mcve)的失敗代碼向我們展示。並請包括您在問題主體中遇到的實際錯誤。 –