zoukankan      html  css  js  c++  java
  • c++无法解析的外部符号 "int const bufferSize

    无法解析的外部符号 "int const bufferSize

    严重性 代码 说明 项目 文件 行 禁止显示状态
    错误 LNK2001 无法解析的外部符号 "int const bufferSize" (?bufferSize@@3HB) c8a_demo d:\Users\TT2018\documents\visual studio 2015\Projects\c8a_demo\c8a_demo\demo2.obj 1

    在demo2中使用demo1的bufferSize常量时,除了在demo2中设置extern const int bufferSize,

    还得在demo1中定义为:extern const int bufferSize(8);

    demo2的文件:

    #include <iostream>
    int bb;
    //bb = 22;
    extern const int bufferSize;
    void foo()
    {
        std::cout << "demo2's bb value is : "<<bb << std::endl;
    
        bb=221;
    }
    void foo1()
    {
        std::cout << "demo2 file is showing: " << bufferSize << std::endl;
    }

    demo1.cpp

     1 #include <iostream>
     2 int aa(11);
     3 extern int bb;
     4 extern int cc;
     5 extern void foo();
     6 extern void foo1();
     7 extern const int bufferSize(8);//此处应该这样设置。
     8 using namespace std;
     9 int main()
    10 {
    11 
    12     bb = 22;
    13 
    14     std::cout << "aa value is : " << aa << std::endl;
    15 
    16     foo();
    17 
    18     std::cout << "bb's second value is : " << bb << std::endl;
    19 
    20     for (int i = 0; i != bufferSize; i++)
    21 
    22         cout << "bufferSize is " << i << endl;
    23 
    24     foo1();
    25 
    26     getchar();
    27 
    28     return 0;
    29 
    30 }


    ————————————————
    版权声明:本文为CSDN博主「txwtech」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/txwtech/article/details/102886602

    欢迎讨论,相互学习。 txwtech@163.com
  • 相关阅读:
    P1522 牛的旅行
    P1908 逆序对
    P1107 雷涛的小猫
    欧拉函数
    P2679 子串
    P1063 能量项链
    P1052 过河
    P1020 导弹拦截
    P1330 阳光封锁大学
    P1198 最大数
  • 原文地址:https://www.cnblogs.com/txwtech/p/11801263.html
Copyright © 2011-2022 走看看