加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 声明但未定义的函数?然而它被定义了

发布时间:2020-12-16 03:24:27 所属栏目:百科 来源:网络整理
导读:header.h namespace VectorMath { static FVector Make(float X,float Y,float Z);} file.cpp namespace VectorMath { static FVector Make(float X,float Z) { FVector ret; ret.X = X; ret.Y = Y; ret.Z = Z; return ret; }} 错误 1c:program files (x86)
header.h
namespace VectorMath {
    static FVector Make(float X,float Y,float Z);
}

file.cpp

namespace VectorMath {
    static FVector Make(float X,float Z)
    {
        FVector ret;
        ret.X = X;
        ret.Y = Y;
        ret.Z = Z;
        return ret;
    }
}

错误

1>c:program files (x86)microsoft visual studio 10.0vcincludexstring(541): error C2129: static function ‘FVector VectorMath::Make(float,float,float)’ declared but not defined
1> c:programming****vectormath.h(19) : see declaration of ‘VectorMath::Make’

错误指向xstring(标准字符串库的一部分)第541行,它似乎与任何东西都没有任何关系.

我想要注意,删除“静态”会给我链接器错误,告诉我“Make”是一个未解析的外部符号……

解决方法

您需要删除静态,否则该函数将在不同的编译单元中不可见.只是用
namespace VectorMath {
    FVector Make(float X,float Z);
}

同样的定义.

如果这不能解决您的链接问题,您需要确保实际编译并正确链接file.cpp,但静态肯定是错误的.

关于您发现问题的注释,在使用内联函数时,您无法将声明与定义分开:是,这与生成的方法符号及其可见性具有类似的效果.我觉得奇怪的是你要求这个作为接受答案的先决条件,尽管你从未在你的问题中提到内联.我怎么会知道你只是添加了你不太懂的随机关键词?这不是帮助您解决问题的其他人的良好基础.您需要发布真实的代码并对我们诚实.如果将来提出更多问题,请记住这一点.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读