image
image

Reputation: 173

Initializing static variables in static function result in unresolved

class PossibilisticShellClustering
{
public:
    PossibilisticShellClustering(void);
    ~PossibilisticShellClustering(void);
    static void SetParameters(double deltaDistance);
    static  double deltaDistance
};

and i wanto to initialize static variable deltaDistance in function SetParameters. So in *.cpp file I wrote

void PossibilisticShellClustering::SetParameters(double deltaDistance)
{
    PossibilisticShellClustering::deltaDistance = deltaDistance;    
}

however I get linker erros

unresolved external symbol "public: static double PossibilisticShellClustering::deltaDistance" (?deltaDistance@PossibilisticShellClustering@@2NA)

Could somebody tell me why ?

PossibilisticShellClustering.obj

Upvotes: 2

Views: 218

Answers (1)

CB Bailey
CB Bailey

Reputation: 792069

You need to defined PossibilisticShellClustering::deltaDistance in a source file somewhere in your program, usually a .cc or .cpp file.

double PossibilisticShellClustering::deltaDistance;

What you have in the class body (or would have if it was terminated with a ;) is only a declaration. Static data members also need a definition.

Upvotes: 2

Related Questions