我在VC6.0中建立了一个由下列三个文件组成的project:
//test.h头文件
#include <iostream>
using namespace std;
class test{
public:
void print(int t);
};
//test.cpp文件
#include "test.h"
void test::print(int n){
for (int t=1;t<=n;t++)
cout<<"**********"<<endl;
}
//main.cpp文件
#include "test.h"
void main(){
test my;
my.print(5);
}
我想知道,main.cpp中只包含了test.h这个头文件,并没有包含test.cpp文件,连接器怎么会知道将print函数的代码连接进程序的.exe文件中呢?
test.cpp需要先编译好,然后将test.obj加入工程,否则链接出错
在同一工程下的文件可以相互访问,这是编译器的优化,