Note that there are some explanatory texts on larger screens.

plurals
  1. PO"undefined reference to" error. (from a member function to static member variable)
    primarykey
    data
    text
    <p>I got a following error upon linking.</p> <p>A member variable ClassBB::THR can't be accessed from a function ClassBB::bound(). </p> <p>What's strange is, from ClassBB::setThreshold(T v) function, which seems in the same condition with ClassBB::bound() in that both are template member function, ClassBB::THR is successfully accessed (I'm only talking about compile time, of course).</p> <p>I'm still new to C++ especially in template architecture. Thanks!</p> <p>Environment: Ubuntu 10.10, G++ 4.4.5 via Eclipse Indigo CDT</p> <p>Error msg (only linker's part):</p> <pre><code>Building target: SampleEclipsePrj Invoking: GCC C++ Linker g++ -L/usr/local/lib -L/usr/lib -o "SampleEclipsePrj" ./src/SampleEclipsePrjFinal/IntersectAngle.o ./src/SampleEclipsePrjFinal/ReadRealTime.o ./src/SampleEclipsePrjFinal/SampleEclipsePrj.o ./src/SampleEclipsePrjFinal/SampleEclipsePrjThread.o ./src/SampleEclipsePrjFinal/Slope.o ./src/SampleEclipsePrjFinal/Transform.o ./src/SampleEclipsePrjFinal/Utility.o ./src/SampleEclipsePrjFinal/main3_linux.o ./src/SampleEclipsePrjFinal/reader.o -lcv -lcxcore -lhighgui ./src/SampleEclipsePrjFinal/SampleEclipsePrj.o: In function `ClassBB&lt;double&gt;::bound()': /home/user/Documents/workspace_eclipse/SampleEclipsePrj/Includes/ClassBB.hpp:203: undefined reference to `ClassBB&lt;double&gt;::THR' /home/user/Documents/workspace_eclipse/SampleEclipsePrj/Includes/ClassBB.hpp:204: undefined reference to `ClassBB&lt;double&gt;::THR' /home/user/Documents/workspace_eclipse/SampleEclipsePrj/Includes/ClassBB.hpp:206: undefined reference to `ClassBB&lt;double&gt;::THR' /home/user/Documents/workspace_eclipse/SampleEclipsePrj/Includes/ClassBB.hpp:207: undefined reference to `ClassBB&lt;double&gt;::THR' collect2: ld returned 1 exit status make: *** [SampleEclipsePrj] Error 1 **** Build Finished **** </code></pre> <p>Note: Got the same result both on Eclipse and terminal.</p> <p>Code-B (snipped to show related part only):</p> <pre><code>#ifndef _BBOUND_H #define _BBOUND_H template&lt;class T&gt; class ClassBB { T *pMap; float u1, v1, u2, v2; int w, h; float converge(float sp, float ep, float steps, float fixedPt, float thr); static T THR; public: ClassBB() : pMap(NULL), u1(0), v1(0), u2(0), v2(0), w(0), h(0) { } ClassBB(float U1, float V1, float U2, float V2); static void setThreshold(T v); int bound(); ~ClassBB(); }; template&lt;class T&gt; ClassBB&lt;T&gt;::ClassBB(float U1, float V1, float U2, float V2) {// do something } template&lt;class T&gt; void ClassBB&lt;T&gt;::setThreshold(T v) { ClassBB::THR = v; } //Converge template&lt;class T&gt; float ClassBB&lt;T&gt;::converge(float sp, float ep, float step, float fixedPt, float thr) {// do something return point; } //The bound algorithm template&lt;class T&gt; int ClassBB&lt;T&gt;::bound() { u2 = converge(0.75, 0.5, 0.03125, v2, ClassBB::THR); v2 = converge(0.25, 0.0, 0.03125, u2, THR); // Both don't work. return 1; } template&lt;class T&gt; ClassBB&lt;T&gt;::~ClassBB() {// do something } #endif </code></pre> <p>Code-C (instantiate the class):</p> <pre><code>#ifndef _SCENE_CLASSIFIER_H #define _SCENE_CLASSIFIER_H #include "ClassBB.hpp" class ClassCC { ClassBB&lt;double&gt; bb; //Branch and Bound public: ClassCC(int W = 0, int H = 0); ~ClassCC(); }; #endif </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.
 

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