Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:42:39+00:00 2026-05-23T21:42:39+00:00

I got a following error upon linking. A member variable ClassBB::THR can’t be accessed

  • 0

I got a following error upon linking.

A member variable ClassBB::THR can’t be accessed from a function ClassBB::bound().

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).

I’m still new to C++ especially in template architecture. Thanks!

Environment: Ubuntu 10.10, G++ 4.4.5 via Eclipse Indigo CDT

Error msg (only linker’s part):

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<double>::bound()':
/home/user/Documents/workspace_eclipse/SampleEclipsePrj/Includes/ClassBB.hpp:203: undefined reference to `ClassBB<double>::THR'
/home/user/Documents/workspace_eclipse/SampleEclipsePrj/Includes/ClassBB.hpp:204: undefined reference to `ClassBB<double>::THR'
/home/user/Documents/workspace_eclipse/SampleEclipsePrj/Includes/ClassBB.hpp:206: undefined reference to `ClassBB<double>::THR'
/home/user/Documents/workspace_eclipse/SampleEclipsePrj/Includes/ClassBB.hpp:207: undefined reference to `ClassBB<double>::THR'
collect2: ld returned 1 exit status
make: *** [SampleEclipsePrj] Error 1

**** Build Finished ****

Note: Got the same result both on Eclipse and terminal.

Code-B (snipped to show related part only):

#ifndef _BBOUND_H
#define _BBOUND_H

template<class T>
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<class T>
ClassBB<T>::ClassBB(float U1, float V1, float U2, float V2)
{// do something
}

template<class T>
void ClassBB<T>::setThreshold(T v)
{
    ClassBB::THR = v;
}

//Converge
template<class T>
float ClassBB<T>::converge(float sp, float ep, float step, float fixedPt,
        float thr)
{// do something
    return point;
}
//The bound algorithm
template<class T>
int ClassBB<T>::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<class T>
ClassBB<T>::~ClassBB()
{// do something
}

#endif

Code-C (instantiate the class):

#ifndef _SCENE_CLASSIFIER_H
#define _SCENE_CLASSIFIER_H
#include "ClassBB.hpp"

class ClassCC
{
        ClassBB<double> bb; //Branch and Bound

    public:
        ClassCC(int W = 0, int H = 0); 
        ~ClassCC(); 
};
#endif
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:42:41+00:00Added an answer on May 23, 2026 at 9:42 pm

    You have to create the storage for the static variable. Just add:

    template<class T> T ClassBB<T>::THR;
    

    Note that for normal member variables, the storage is generated whenever a new instance of the template class is created. But for static members, a “static” place should be defined for them, hence the explicit definition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

GOT error for the following query in MYSQL(version5.1) SELECT year,month,sum(fact_1),sum(fact_2),sum(fact_3),sum(fact_4) from( select year,month,fact_1,fact_2,0 as
I got the following SQLException: invalid options in all7 Upon googling the error message,
I got following error... System.NullReferenceException: Object reference not set to an instance of an
I tried installing TurboGears 1.0 on Windows 7 using tgsetup.py. and got following error
I got the following error of Oracle, ORA-25226: dequeue failed, queue string.string is not
While working on an existing project I suddenly got the following error when trying
Whenever I run any jython program in Eclipse, I got the following error in
I tried to update some part of a matrix, I got the following error
I get the following error: ActiveRecord::AssociationTypeMismatch in ContractsController#create ExchangeRate(#2183081860) expected, got HashWithIndifferentAccess(#2159586480) Params: {commit=>Create,
I got error Access Violation when the following code is execute : void NoAction()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.