积极答复者
请教关于C++里包含文件会重复的问题

问题
-
请问下面这样会重复包含文件吗?
我定义了两个类,一个img,一个sound;有5个文件,分别为:img.h、img.cpp、sound.h、sound.cpp、main.cpp
//img.h
#include <iostream>
......
//img.cpp
#include"img.h"
//sound.h
#include<iostream>
.....
//sound.cpp
#include"sound.h"
//main.cpp
#include"img.h"
#include"sound.h"
这种情况会不会造成重复包含文件?就是在main.cpp中会不会重复包含了iostream.h?
答案
全部回复
-
1) #include "……" 要写在 #pragma once 下面
2) 要善于利用预编译头文件,把大家都需要包含的头文件写到stdAfx.h 文件中- 已建议为答案 Nancy Shao 2010年2月25日 8:01