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

  • 相关阅读:
    谈谈团队文化
    ubifs性能优化分析
    ubifs总体设计分析
    分层网络模型(二)
    哎,老了之display-box
    http协议
    box-shadow,text-shadow
    nth-child,nth-last-child,after,before,tab-highlight-color,first-child,last-child
    转载之html特殊字符的html,js,css写法汇总
    一天学习一点之express demo
  • 原文地址:https://www.cnblogs.com/cy163/p/1930956.html
Copyright © 2011-2022 走看看