假设你的程序中有main.cpp,first.cpp,Query.h,first.h等文件。
在main.cpp中有
#include"Query.h"
#include"first.h"
在first.cpp中有
#include"first.h"
在first.h中有
#include"Query.h"
那么在main与first文件中就会有相同的函数定义,这个错误应该是链接错误的。经过编译形成的main.obj,与first.obj中都会有、同一个函数的定义与代码、当 链接时就会出现重定义。
这个例子 #ifndef 的作用在main.cpp中,因为已经有Query.h了,所以在first.h中包含的Query.h是不会包含于main.cpp中的、