Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with linking .cpp files in Code::Blocks
    text
    copied!<p>I'm having a headerfile called <em>cnVector.h</em> whose implementation is written in <em>cnVector.cpp</em>. Those two files are located in the same directory.</p> <pre><code>cNormalCBP/ + src/ + cNormal/ + cnUtils/ - cnVector.h - cnVector.cpp - main.cpp </code></pre> <p>The header contains a simple class definition.</p> <pre><code>class cnVector { public: cnVector(double, double, double); inline cnVector cross(const cnVector&amp;) const; }; </code></pre> <p>The implementation in the <em>.cpp</em> file is as follows:</p> <pre><code>#include "cnVector.h" /* constructor */ cnVector::cnVector(double x, double y, double z) : x(x), y(y), z(z) { } cnVector cnVector::cross (const cnVector&amp; vOther) const { return cnVector( y * vOther.z + z * vOther.y, z * vOther.x + x * vOther.z, x * vOther.y + y * vOther.x ); } </code></pre> <p>Now, the following code from <em>main.cpp</em> breaks at line <strong>3</strong> because of an <em>undefined reference to cnVector::cross(cnVector const&amp;) const;</em><br> Note how the constructor-implementation is recognized, but not the <code>cnVector::cross</code> method.</p> <pre><code>int main() { cnVector v1(1, 0, 0), v2(0, 1, 0); cnVector v3 = v1.cross(v2); } </code></pre> <p>I also get an error-message <em>warning: inline function 'cnVector cnVector::cross(const cnVector&amp;) const' used but never defined</em>.<br> Copying the implementation into <em>main.cpp</em> works.</p> <blockquote> <p>Can you explain to me why I can construct a <em>cnVector</em> instance but the implementation of other methods are not recognized ?</p> </blockquote>
 

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