編譯程式警告 (層級 2) C5046
'function' :未定義內部連結之型別的符號
備註
編譯程式偵測到使用沒有定義的函式,但此函式的簽章牽涉到在此轉譯單位外部看不到的類型。 因為這些類型在外部看不到,所以沒有其他轉譯單位可以提供此函式的定義,因此無法成功連結程式。
在翻譯單位之間看不到的類型包括:
匿名命名空間內宣告的類型
本機或未命名的類別
使用這些類型做為範本自變數的範本特製化。
此警告是Visual Studio 2017 15.8版的新功能。
範例
此範例顯示兩個 C5046 警告:
// C5046p.cpp
// compile with: cl /c /W2 C5046p.cpp
namespace {
struct S {
// S::f is inside an anonymous namespace and cannot be defined outside
// of this file. If used, it must be defined somewhere in this file.
int f();
};
}
// g has a pointer to an unnamed struct as a parameter type. This type is
// distinct from any similar type declared in other files, so this function
// cannot be defined in any other file.
// Note that if the struct was declared "typedef struct { int x; int y; } S, *PS;"
// it would have a "typedef name for linkage purposes" and g could be defined
// in another file that provides a compatible definition for S.
typedef struct { int x; int y; } *PS;
int g(PS p);
int main()
{
S s;
s.f(); // C5046 f is undefined and can't be defined in another file.
g(nullptr); // C5046 g is undefined and can't be defined in another file.
}
若要修正這些問題,請定義此檔案中的函式。