久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C++類頭文件組織

C++ class header files organization(C++類頭文件組織)
本文介紹了C++類頭文件組織的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

對于必須處理分布在多個源文件和頭文件中的大量相互依賴的類的人,您建議的 C++ 編碼和文件組織指南是什么?

What are the C++ coding and file organization guidelines you suggest for people who have to deal with lots of interdependent classes spread over several source and header files?

我在我的項目中遇到了這種情況,解決跨多個頭文件的類定義相關錯誤已經變得非常令人頭疼.

I have this situation in my project and solving class definition related errors crossing over several header files has become quite a headache.

推薦答案

一些通用指南:

  • 將您的接口與實現配對.如果您有 foo.cxx,那么在其中定義的所有內容最好在 foo.h 中聲明.
  • 確保每個頭文件#include 獨立編譯所需的所有其他必要的頭文件或前向聲明.
  • 抵制創建一切"標題的誘惑.他們總是在路上遇到麻煩.
  • 將一組相關(和相互依賴)的功能放入一個文件中.Java 和其他環境鼓勵每個文件一個類.對于 C++,您通常希望每個文件有一組 類.這取決于您的代碼結構.
  • 盡可能優先使用前向聲明而不是 #include.這允許您打破循環頭依賴關系.本質上,對于跨單獨文件的循環依賴,您需要一個看起來像這樣的文件依賴圖:
    • A.cxx 需要 A.hB.h
    • B.cxx 需要 A.hB.h
    • A.h 需要 B.h
    • B.h 是獨立的(并且前向聲明在 A.h 中定義的類)
    • Pair up your interfaces with implementations. If you have foo.cxx, everything defined in there had better be declared in foo.h.
    • Ensure that every header file #includes all other necessary headers or forward-declarations necessary for independent compilation.
    • Resist the temptation to create an "everything" header. They're always trouble down the road.
    • Put a set of related (and interdependent) functionality into a single file. Java and other environments encourage one-class-per-file. With C++, you often want one set of classes per file. It depends on the structure of your code.
    • Prefer forward declaration over #includes whenever possible. This allows you to break the cyclic header dependencies. Essentially, for cyclical dependencies across separate files, you want a file-dependency graph that looks something like this:
      • A.cxx requires A.h and B.h
      • B.cxx requires A.h and B.h
      • A.h requires B.h
      • B.h is independent (and forward-declares classes defined in A.h)

      如果您的代碼旨在成為其他開發人員使用的庫,則需要采取一些額外的步驟:

      If your code is intended to be a library consumed by other developers, there are some additional steps that are important to take:

      • 如有必要,請使用私有標頭"的概念.也就是說,幾個源文件需要的頭文件,但公共接口從來不需要.這可以是包含常見內聯函數、宏或內部常量的文件.
      • 在文件系統級別將公共接口與私有實現分開.我傾向于在我的 C 或 C++ 項目中使用 include/src/ 子目錄,其中 include/ 包含我所有的公共頭文件,并且 src/ 有我所有的來源.和私人標題.
      • If necessary, use the concept of "private headers". That is, header files that are required by several source files, but never required by the public interface. This could be a file with common inline functions, macros, or internal constants.
      • Separate your public interface from your private implementation at the filesystem level. I tend to use include/ and src/ subdirectories in my C or C++ projects, where include/ has all of my public headers, and src/ has all of my sources. and private headers.

      我建議您找一本 John Lakos 的書大規模 C++ 軟件設計.這是一本相當厚重的書,但如果您只是瀏覽他關于物理建筑的一些討論,您會學到很多東西.

      I'd recommend finding a copy of John Lakos' book Large-Scale C++ Software Design. It's a pretty hefty book, but if you just skim through some of his discussions on physical architecture, you'll learn a lot.

      這篇關于C++類頭文件組織的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

      【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 国产91网站在线观看 | 欧美成年网站 | 日韩在线一区二区 | 色视频网站免费 | 日韩成人免费视频 | 美美女高清毛片视频免费观看 | 91久久精品一区二区二区 | www国产亚洲精品久久网站 | 国产精品一区二区三区四区五区 | 免费在线一区二区三区 | 久久av网 | 精品免费国产视频 | 精品成人佐山爱一区二区 | a黄视频 | 国产精品免费观看 | 亚洲淫视频 | 精品国产一区二区在线 | 91中文字幕在线 | 精品91久久| 日批免费观看 | 亚洲精品小视频在线观看 | 日日射影院 | 草草视频在线播放 | 国产精品美女久久久久久免费 | 亚洲福利视频一区二区 | 日韩高清国产一区在线 | 一区二区国产精品 | 国产精品亚洲一区 | 国产高清视频 | 国产激情91久久精品导航 | 国产69精品久久99不卡免费版 | 日韩av成人在线 | 91久久精品一区二区二区 | 亚洲一区二区三区在线播放 | 丝袜一区二区三区 | 国产成人一区二区三区久久久 | 给我免费的视频在线观看 | 国产免费又黄又爽又刺激蜜月al | 91观看| 国产精品一区二区在线播放 | 密室大逃脱第六季大神版在线观看 |