• 1、error LNK2019: 无法解析的外部符号“struct ********“


    一、C++ 错误类型 :error LNK2019 无法解析的外部符号

    **注:本人用的编译器版本:VS2015

    C++中报 error LNK2019、LNK2001、......等类型的错误,对刚接触C++的同学来说是一件非常令人头疼的事情,因为造成此类问题的原因非常多,这里只讲本人报错的一种原因。

    二、报错截图

    三、报错原因

    1、本人是因为函数声明  accumulate 与函数实现名 acculate 称不一致导致报 error LNK2019 错。

    2、在声明函数  accumulate(......)  的时候,未将该函数实现,导致报错,这是造成  error LNK2019 错误原因的一种;

    报错前的代码:

    1. 1 free_throws& accumulate(free_throws& target, const free_throws& source); // 函数声明
    2. 2
    3. 3 int main() // 主函数
    4. 4 {
    5. 5 ...........
    6. 6 }
    7. 7
    8. 8 free_throws& acculate(free_throws & target, const free_throws & source) // 函数实现
    9. 9 {
    10. 10 target.attempts += source.attempts;
    11. 11 target.made += source.made;
    12. 12 set_pc(target);
    13. 13 return target;
    14. 14 }

    四、解决办法

    1.首先检查所声明的所有函数都有没有实现;

    2.检查声明函数与实现函数的函数名、参数列表、返回值是否一致;

    3.检查后期自己是否有修改过函数名,导致声明函数名与实现函数名不一致

    修改后的代码:

    1. 1 free_throws& accumulate(free_throws& target, const free_throws& source); // 函数声明
    2. 2
    3. 3 int main() // 主函数
    4. 4 {
    5. 5 ...........
    6. 6 }
    7. 7
    8. 8 free_throws& accumulate(free_throws & target, const free_throws & source) // 函数实现
    9. 9 {
    10. 10 target.attempts += source.attempts;
    11. 11 target.made += source.made;
    12. 12 set_pc(target);
    13. 13 return target;
    14. 14 }

    五、总结

    此类错误不太容易发现,读者在敲代码时尽量细心,犯错之时,要学会总结,利用好手上的工具。

    希望可以帮助到各位!

  • 相关阅读:
    实验三 Servlet 相关技术
    JVM优化案例实战-手动模拟Young GC
    【pod进阶】
    NTLM与kerberos认证体系详解
    MaxCompute远程连接,上传、下载数据文件操作
    vue 项目打包性能分析插件 webpack-bundle-analyzer
    KingbaseESV8R6等待事件之lwlock buffer_content
    2022年8月叙利亚再次因国考全国断网
    Chapter 3 New Optimizers for Deep Learning
    Unity的BuildPlayerProcessor:深入解析与实用案例
  • 原文地址:https://blog.csdn.net/Erudite_x/article/details/126002660