Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In C++ source files are conceptually completely separate from class definitions.</p> <p><code>#include</code> and header files work at a basic text level. <code>#include "myfile"</code> simply includes the contents of the file <code>myfile</code> at the point at which the include directive is placed.</p> <p>Only after this process has happened is the resulting block of text interpreted as C++ code. There is no language requirement that a class called <code>Book</code> has to be defined in a file called <code>Book.h</code>. Although it is highly recommended that you do follow such a convention, it's essential to remember that it's not a given when debugging missing declaration or definition issues.</p> <p>When parsing your <code>Library.h</code> file the compiler must have seen a declaration for the identifier <code>Book</code> at the point at which it is used in the defintion of the class <code>Library</code>.</p> <p>As you are only declaring a member variable of type "pointer to <code>Book</code>", you only need a declaration and not a full definition to be available so if <code>Book</code> is a class then the simplest 'fix' is to add a forward declaration for it before the definition of <code>Library</code>.</p> <p>e.g.</p> <pre><code>class Book; class Library { // definition as before }; </code></pre> <p><strong>Include Guards</strong></p> <p>It looks like you may have some include guard errors. Because you can only define classes once per translation units the definitions inside header files are usually protected with include guards. These ensure that if the same header is included multiple times via different include files that the definitions it provides aren't seen more than once. Include guards should be arranged something like this. Looking at your <code>Library.h</code>, it may be that your include guards are not terminated correctly.</p> <p>myclass.h:</p> <pre><code>#ifndef MYCLASS_H #define MYCLASS_H class MyClass { }; // The #ifndef is terminated after all defintions in this header file #endif //MYCLASS_H </code></pre>
 

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