在vs中,使用c時,由編譯-連接,cpp之間是自動的,如:spa
1,頭文件 x.h:code
1 int f();
2,實現 impl.cpp:blog
1 #include "stdafx.h" 2 3 int f() { 4 return 1; 5 }
3,在main(即user_extern.cpp)中(使用實現 impl.cpp不須要include impl.cpp),只要include 包含 int f();的 頭文件(即 x.h)編譯
1 // user_extern.cpp : 定義控制檯應用程序的入口點。 2 // 3 4 #include "stdafx.h" 5 #include "x.h" 6 7 8 int _tmain(int argc, _TCHAR* argv[]) 9 { 10 int i= f(); 11 printf("%d",i); 12 return 0; 13 }