C++ 外表古怪的行为
可能重复:C++ 外表古怪的行为,c++,linker,constants,extern,C++,Linker,Constants,Extern,可能重复: 这段代码将在c语言中产生错误++ // Foo.cpp const int Foo = 99; // Main.cpp extern const int Foo; int main() { cout << Foo << endl; return 0; } //Foo.cpp const int Foo=99; //Main.cpp 外务工程及内部财务; int main() { cout在CPP中添加了一个extern…行,我认为
这段代码将在c语言中产生错误++
// Foo.cpp
const int Foo = 99;
// Main.cpp
extern const int Foo;
int main()
{
cout << Foo << endl;
return 0;
}
//Foo.cpp
const int Foo=99;
//Main.cpp
外务工程及内部财务;
int main()
{
cout在CPP中添加了一个extern…
行,我认为这会杀死下一行的内部链接行为
// Foo.cpp
extern const int Foo;
const int Foo = 99;
还对主要问题进行了一些不相关的更正:
// Main.cpp
#include <iostream>
extern const int Foo;
int main()
{
using namespace std;
cout << Foo << endl;
return 0;
}
//Main.cpp
#包括
外务工程及内部财务;
int main()
{
使用名称空间std;
你不是在大约2小时前问过同样的问题吗?你读过那里的答案了吗?如果你对之前问过的问题仍然有疑问,你应该把你的疑问作为评论添加到答案中,而不是开始一个新的问题。@als我认为消除别人的疑问是最好的做法。好吧,不要一次又一次地问同样的问题,如果您不理解答案,请在答案下的评论部分提出疑问,不要再问其他问题。请阅读SO FAQ.UPDATE:如果您将const int Foo=99
写入Foo.cpp,这也是正确的。Als引用的帖子解释了这一点。
// Main.cpp
#include <iostream>
extern const int Foo;
int main()
{
using namespace std;
cout << Foo << endl;
return 0;
}