gpt4 book ai didi

c++ - C++ 中的 Extern (VS2012) 找到多个定义的符号

转载 作者:行者123 更新时间:2023-11-28 03:23:13 25 4
gpt4 key购买 nike

<分区>

我的代码在这里:

Header.h文件:

#ifndef HEADER_H_
#define HEADER_H_

extern int k;

#endif /* HEADER_H_ */

Source1.h 文件:

#include <iostream>
#include "Header.h"
using namespace std;

#ifndef SOURCE1_H_
#define SOURCE1_H_

int k = 10;

void punch(){
cout << k << endl;
}

#endif /*SOURCE1_H_*/

源.cpp文件:

#include "Source1.h"
using namespace std;

int main()
{
punch();
cin.get();
return 0;
};

我在 Windows 7 的 Visual Studio 2012 Express Edition 上编译。错误代码是:

1>c:\users\freeman\documents\visual studio 2012\Projects\exploringexterns\Debug\exploringexterns.exe : fatal error LNK1169: one or more multiply defined symbols found

我做错了什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com