编译器警告(等级 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.
}

若要修复这些问题,请定义此文件中的函数。