zoukankan      html  css  js  c++  java
  • 为解决多次Include 某头文件

    为解决多次Include 某头文件

     方法1:

    //使用名字来防止重复包含 

    #ifndef __TXML_H
    #define __TXML_H

    //code write here

    #endif
    __TXML_H

    这种名称只是一个唯一标识,C的习惯写法

    what if the identify is not the only one

    if you have the following

    //Txml.h
    #ifndfe __TXML_H
    #define __TXML_H

    #endif

    //==========
    //Vxml.h
    #ifndfe __TXML_H
    #define __TXML_H //which is not only one now

    #endif

    //==========
    //useage in mainTest.cpp:

    #include 
    "Txml.h"
    #include 
    "Vxml.h"

    int main()
    {
      Txml 
    *pTobj= new Txml();
      Vxml 
    *pVobj= new Vxml();//error here : not define
    }
    //==========
    /*
    reason for not define;
    when comply ,complier will not include Vxml.h because 
    #ifndfe __TXML_H //which is FALSE 
    #define __TXML_H  
    */

     方法2:

    #pragma once

     //使用文件物理位置来防止重复包含

  • 相关阅读:
    小技巧:通过linux一行命令修改ip
    小技巧:textarea文本输入区内实现换行
    set 排序实例
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
  • 原文地址:https://www.cnblogs.com/no7dw/p/2067504.html
Copyright © 2011-2022 走看看