共用方式為


編譯器錯誤 C2893

無法特製化函式範本 'template name'

編譯程式無法特製化函式範本。 許多原因都可能造成此錯誤。

一般而言,解決 C2893 錯誤的方式是檢閱函式的簽章,並確定您可以具現化每個類型。

範例

C2893 之所以發生,是因為 f的樣板參數 T 被推斷為 std::map<int,int>,但沒有 std::map<int,int> 成員 data_typeT::data_type 無法使用 具現化 T = std::map<int,int>。 下列範例會產生 C2893。

// C2893.cpp
// compile with: /c /EHsc
#include <map>
using namespace std;
class MyClass {};

template<class T>
inline typename T::data_type
// try the following line instead
// inline typename  T::mapped_type
f(T const& p1, MyClass const& p2);

template<class T>
void bar(T const& p1) {
    MyClass r;
    f(p1,r);   // C2893
}

int main() {
   map<int,int> m;
   bar(m);
}