C/C++ 部分
1. pragma once 跟 ifndef 的區別
2. 變量或者函數在連接的時候被多處定義的問題
描述:如有文件head.hpp, test.cpp, main.cpp
//File haed.hpp
#include<string>
void foo()
{
}
std::string testStr="abc";
const std::string constStr="js";
void test();
#endif
//File test.cpp
#include"head.hpp"
void test()
{
}
//File main.cpp
#include"head.hpp"
int main()
{
}
問題是分別編譯test.cpp跟main.cpp生產.o目標文件沒問題,鏈接test.o main.o生成最終的可執行文件時候foo函數在多處定義, string testStr也在多處定義,爲啥const的constStr沒有問題呢?