Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You seem to be confusing the concepts of source file and include file.</p> <p>Simply explained, in C++ you have two types of files:</p> <ul> <li>Source files contain source code. This is the code that will be executed in your application. Source files typically have the extension .CPP.</li> <li>Include files contain declarations. They only describe the elements in your application, but don't contain source code. Include files typically have the extension .H.</li> </ul> <p>Source files can include include files, and include files can include other include files. Source files are never included in other files. They are compiled and linked together.</p> <p>In your case, the include of "Extending.cpp" in form1.h is clearly incorrect.</p> <p>Try to split your code into clear include files and source files. This means:</p> <ul> <li>FORM1.H which contains the class declaration, but no source code</li> <li>FORM1.CPP which contains the code of your form class</li> <li>EXTENDING.H which contains the class declaration, but no source code</li> <li>EXTENDING.CPP which contains the source code of the Extending class</li> </ul> <p>You will notice that FORM1.H will not need EXTENDING.H and vice versa.</p> <p>On the other hand, FORM1.CPP may require both FORM1.H and EXTENDING.H, and probably EXTENDING.CPP may require both FORM1.H and EXTENDING.H, but that's not a problem.</p> <p>Now compile both CPP files and link them together.</p> <p>Once you gained more experience with C++ you will see that it is indeed possible to put source code in include files (to make inlining possible) and to have circular dependencies (using forward declarations), but first start gaining more experience with C++.</p> <p><strong>EDIT:</strong></p> <p>If there is something in Form1 that needs EXTENDING.H, it can be one of the following cases:</p> <ul> <li>You have an inline method which needs the definition of the Extending class --> move the method to form1.cpp.</li> <li>You have a member in Form1 that is a pointer to the Extending class --> use forward declarations (the compiler doesn't really need to know the complete definition of a class to be able to generate code for storing the pointer)</li> <li>You have a member in Form1 that is an instance of Extending --> then you really need to include EXTENDING.H in FORM1.H</li> <li>Your Form1 class inherits from Extending --> then you really need to include EXTENDING.H in FORM1.H</li> <li>There is a data type in Form1 that needs the definition of something in Extending (could be an enumeration) --> then you really need to include EXTENDING.H in FORM1.H</li> </ul> <p>Check the same for the other way around.</p> <p>If you still have a circular dependency, pull out the members that cause the dependency and put them in a different class, which can then be used by both EXTENDING.H and FORM1.H.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload