请问hpw确保只有一个文件的副本ia#包含在complilation中? [英] Pls hpw does one ensure that only one copy of a file ia # included in the complilation?

查看:103
本文介绍了请问hpw确保只有一个文件的副本ia#包含在complilation中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当多个文件和基类文件需要mfc应用程序中的同名文件时,请确保只有一个文件的副本ia#包含在complilation中。

我一直在争夺这个compliler继续抱怨重新定义。

Pls hpw does one ensure that only one copy of a file ia # included in the complilation when several files and base class file require thesame file in an mfc application.
I have been battling this all day.The compliler keep complaining of a redefinition.

推荐答案

在.H文件中保护顶部和底部像这样



In the .H file put protection top and bottom like this

// PROTECTION TO STOP MULTIPLE UNIT LOADING
#ifndef _MYUNIT_									
#define _MYUNIT_

// YOUR NORMAL CURRENT .H DATA HERE

#endif





我总是使用_UNITNAME_为每个单位作为标准,这几乎是标准的方法来做到这一点。如果你有过深思熟虑,那么你只需要查看编译器系统中include目录中的那些,这通常会做同样的事情:-)



这是Visual Studio 12&中的strings.h的顶部。 13



I always use _UNITNAME_ for each and every unit as a standard and that is the almost standard way to do it. If you had of thought hard you would have simply gone at looked at the ones in the include directory on your compiler system which will usually do the same thing :-)

This is the top of strings.h in Visual Studio 12 & 13

/***
*string.h - declarations for string manipulation functions
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       This file contains the function declarations for the string
*       manipulation functions.
*       [ANSI/System V]
*
*       [Public]
*
****/

#pragma once

#ifndef _INC_STRING
#define _INC_STRING


在头文件中使用标题保护:

Use header guard in the header file:
#ifndef _HEADER_NAME_
#define _HEADER_NAME_
...
...
...
#endif



第一次加载此标头时,定义了 _HEADER_NAME _ 。这样就无法重新定义。


When the first time this header is loaded, _HEADER_NAME_ is defined. So that prevents redefinition.


这篇关于请问hpw确保只有一个文件的副本ia#包含在complilation中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆