Problem with linking in Borland Builder C++ 5

D

Dariusz Plygawko

Welcome,
When I'am trying to call static function(setAreaLoader) from other class, I
get following linker-error. How to solve it? I'm slowly getting crazy... And
I have the same problem with the rest of static members... Help me!

[Linker Error] Unresolved external 'Area::m_loader' referenced from
C:\DAREK\NAVIGATOR\AREA.OBJ

***Area.h:***

#ifndef area_H
#define area_H

#include <vcl.h>
#include "Map.h"
#include "AreaLoader.h"

class Area
{

private:
Map * m_maps;
int m_mapsNumber;
public:
Area();
~Area();
static void setAreaLoader(AreaLoader * p_loader);
static Area * createAreaWithLoader(AnsiString p_areaId);
static AreaLoader * m_loader;
};
#endif

***area.cpp:***

#include "Area.h"

....

void Area::setAreaLoader(AreaLoader * p_loader)
{
m_loader = p_loader;
}

....

Best Regards,
Dariusz
 
J

Josephine Schafer

Dariusz Plygawko said:
Welcome,
When I'am trying to call static function(setAreaLoader) from other class, I
get following linker-error. How to solve it? I'm slowly getting crazy... And
I have the same problem with the rest of static members... Help me!

[Linker Error] Unresolved external 'Area::m_loader' referenced from
C:\DAREK\NAVIGATOR\AREA.OBJ

***Area.h:***

#ifndef area_H
#define area_H

#include <vcl.h>
#include "Map.h"
#include "AreaLoader.h"

class Area
{

private:
Map * m_maps;
int m_mapsNumber;
public:
Area();
~Area();
static void setAreaLoader(AreaLoader * p_loader);
static Area * createAreaWithLoader(AnsiString p_areaId);
static AreaLoader * m_loader;
};
#endif

***area.cpp:***

#include "Area.h"

...

void Area::setAreaLoader(AreaLoader * p_loader)
{
m_loader = p_loader;
}
You have just declared Area::m_loader, not defined it.You need to
define it in an implementation file (area.cpp) like
Area::m_loader = .... // define m_loader
You try to access it in Area::setAreaLoader without defining it, so you
know why you are getting the linker error.
 
J

John Harrison

You have just declared Area::m_loader, not defined it.You need to
define it in an implementation file (area.cpp) like
Area::m_loader = .... // define m_loader

Actually like this

AreaLoader* Area::m_loader = ...;

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top