unresolved external

M

Mark

I'm trying to write an RAS class on windows ad RasDial's callback
function requires it to either not be a class member or for it to be
static. I went for the static option so in the header file I declared an
extern variable for the class outside of the class definition so I
could use it in the static function, like so:

#ifndef RasClientH
#define RasClientH

#include <ras.h>
#include <raserror.h>

class RasClient
{
[snip]
};

extern RasClient ras;

#endif

then in the header file for the class I will be using ras in I put:

#ifndef MainFormH
#define MainFormH

#include "RasClient.h"

[snip]

class TfrmMain : public TForm
{
[snip]
private: // User declarations
RasClient ras;
[snip]
};

#endif

but when it's linking I'm getting an error saying '[Linker Error]
Unresolved external '_ras' referenced from RASCLIENT.OBJ'. Can anyone
tell me what I'm doing wrong?

TIA
 
S

Stephan Hoffmann

Mark said:
I'm trying to write an RAS class on windows ad RasDial's callback
function requires it to either not be a class member or for it to be
static. I went for the static option so in the header file I declared an
extern variable for the class outside of the class definition so I
could use it in the static function, like so:

#ifndef RasClientH
#define RasClientH

#include <ras.h>
#include <raserror.h>

class RasClient
{
[snip]
};

extern RasClient ras;
This extern declaration tells the compiler that a global object
with name ras exists. It does not define (instantiate) it.
You do not instantiate it anywhere in the code you showed.
Just add

RasClient ras;

in one of your implementation files. That should solve your linker
problem, but I'm not sure it's really what you want to do.

Stephan
 
M

Mark

Stephan said:
This extern declaration tells the compiler that a global object
with name ras exists. It does not define (instantiate) it.
You do not instantiate it anywhere in the code you showed.
[snip]

So declare it outside of a class definition?

Mark
 
P

Peter_Julian

| Stephan Hoffmann wrote:
| > This extern declaration tells the compiler that a global object
| > with name ras exists. It does not define (instantiate) it.
| > You do not instantiate it anywhere in the code you showed.
| [snip]
|
| So declare it outside of a class definition?
|
| Mark

No, define it outside the class definition.
 

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,009
Latest member
GidgetGamb

Latest Threads

Top