zoukankan      html  css  js  c++  java
  • Vc++ 6.0 如何避免重复包含一个头

    有下面的自定义结构体,定义在sample.h中。

    --------------------------------------------

    typedef struct sample{

     int trueNumber;

     double feature[13];

    }SAMPLE;

    --------------------------------------------

     

    A,类B#include<sample.h>,主程序都调用了类A,类B;就会出现

     

    error C2011: ''sample'' : ''struct'' type redefinition

     

    解决方法:写上宏定义:

     

    -----------------------------------

    #ifndef sample_H_H

    #define  sample_H_H

       typedef struct sample{

       int trueClass;

       double feature[13];

      }SAMPLE;

    #endif

    ---------------------------------------

     

    也可以这样写

     

    ----------------------------------

    #if !define sample_H_H

    #define sample_H_H

       typedef struct sample{

       int trueClass;

       double feature[13];

      }SAMPLE;

    #endif

    -------------------------------

     

    意思是:

     

     

    if(sample_H_H,没有被定义过)

    {

          定义宏sample_H_H

          ........(执行)other code

    }

    实际上sample_H_H作为一个标记而存在

     

     

    自定义一个类时,在所有的头文件中都应用这组宏处理

    注意是#ifndef不是#ifdef

     

    -----------------------------------

    #ifndef 标记名(常以类名_H_H,两个标记名要相同)

    #define  标记名

     

    //你原来的文件内容

     

    #endif

    ---------------------------------

     

    文章出处:飞诺网(www.firnow.com):http://dev.firnow.com/course/3_program/vc/vc_js/20100630/263391.html

  • 相关阅读:
    最详细win7下手动搭建PHP环境:apache2.4.23+php7.0.11
    读书笔记:《HTML5开发手册》Web表单
    jQuery点击图片弹出大图遮罩层
    数据库之一
    Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
    PHP实现RTX发送消息提醒
    angularJS(3)
    angularJS(2)
    替换
    事务格式
  • 原文地址:https://www.cnblogs.com/cy163/p/1930956.html
Copyright © 2011-2022 走看看