Correct use # include and pre-declaration (forward declaration)
When I add a class to the project, and that class is related to the class in the project, such as the member variable of that type. The situation is as follows:
/// //. H // class {.......}; /// // B. h // class B: {.... A member;} The result indicates that A class A cannot be found. The solution is to # include "A. h" in B. h ". But sometimes you don't need to # include "A. h". You just need to add class A; before classB:. More seriously, we should not only # include "A. h", but also class ;. At first, I thought it was okay, because it was always compiled and passed, and it won't make the program bigger, because there is # ifndef... # endif and # pragma once control. Until one time, I needed to put those constants in a file, "const. h ", and then include it to other classes that need it. The result cannot be compiled. (because there are too many files, and every file has to include each other, I am also blinded) until today, I finally found the principle in Objective C ++. I would like to share with you an example of the class structure below. (No matter why I don't add a Woman, why does Man have child? I just give an example to illustrate that there is no gender discrimination. The Code is as follows: /// // Main. h ////////////// # Include "Stdafx. h" # Include "Man. h" Int Main (){ Man m; Return 0; } /// // Person. h ///////////// # Pragma Once Class Person { Public : Person (Void); ~ Person (Void); }; /// // Person. cpp /////////// # Include "StdAfx. h" # Include ". Person. h" Person: Person (Void){ } Person ::~ Person (Void){ } //// // Man. h /////////// # Pragma Once # Include "Person. h" Class Man: Public Pe