Note that there are some explanatory texts on larger screens.

plurals
  1. POC++: Including header-file fails compilation but including source cpp file compiles
    primarykey
    data
    text
    <p>This is probably really simple, but it's hindering me on my way down c++ road. I am currently reading through accelerated c++ and I decided to overkill one of the exercises. It all worked well and my code ran fine until I split it into a header and separate source file. When I import my .cpp source file containing some functions I wrote, everything runs fine. But when I try to import the functions through a header file it fails horribly and I get the following error. I am compiling with gcc from Geany, it's all worked fine until now. Thanks for any help.</p> <p>error:</p> <pre><code>g++ -Wall -o "quartile" "quartile.cpp" (in directory: /home/charles/Temp) Compilation failed. /tmp/ccJrQoI9.o: In function `main': quartile.cpp:(.text+0xfd): undefined reference to `quartile(std::vector&lt;double, std::allocator&lt;double&gt; &gt;)' collect2: ld returned 1 exit status </code></pre> <hr> <p>"stats.h":</p> <pre><code>#ifndef GUARD_stats_h #define GUARD_stats_h #include &lt;vector&gt; std::vector&lt;double&gt; quartile(std::vector&lt;double&gt;); #endif </code></pre> <hr> <p>"stats.cpp":</p> <pre><code>#include &lt;vector&gt; #include &lt;algorithm&gt; #include "stats.h" using std::vector; using std::sort; double median(vector&lt;double&gt; vec){ //code... } vector&lt;double&gt; quartile(vector&lt;double&gt; vec){ //code and I also reference median from here. } </code></pre> <p>"quartile.cpp":</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include "stats.h" //if I change this to "stats.cpp" it works using std::cin; using std::cout; using std::vector; int main(){ //code and reference to quartile function in here. } </code></pre>
    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.
 

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