How to resolve this register method address question?

A

Allen

// 1. RPCMethodRegistry.h

typedef int (*RPCMethod)(CRPCParaPacker& packer);

class CRPCMethodEntry
{
public:
int id;
RPCMethod method;
};

class CRPCMethodRegistry
{
private:
CRPCMethodRegistry(void);
CRPCMethodRegistry(CRPCMethodRegistry const&); // No copy
constructor.
CRPCMethodRegistry& operator=(CRPCMethodRegistry const&); // No
assignment.

public:
static CRPCMethodRegistry& GetInstance(void);
virtual ~CRPCMethodRegistry(void);

public:
inline int RegisterMethod(const int nId, const RPCMethod pMethod);
RPCMethod GetMethod(const int nId);

private:
static CRPCMethodEntry entries[256];
static CRPCMethodRegistry instance;
};

// 2. RdbRegistry.h

class CRdbRegistry
{
public:
CRdbRegistry(void);
~CRdbRegistry(void);

public:
static int TestMethod1(CRPCParaPacker& packer);
static int TestMethod2(CRPCParaPacker& packer);
static int TestMethodN(CRPCParaPacker& packer);
};

// 3. RdbRegistry.cpp
CRdbRegistry::CRdbRegistry(void)
{
CRPCMethodRegistry& registry = CRPCMethodRegistry::GetInstance();
registry.RegisterMethod(0, TestMethod1);
registry.RegisterMethod(1, TestMethod2);
registry.RegisterMethod(2, TestMethodN);
}

VS2005 tells a link error, cannot resolute external symbol public: int
__thiscall CRPCMethodRegistry::RegisterMethod(int,int (__cdecl*const)
(class CRPCParaPacker &))" (?
RegisterMethod@CRPCMethodRegistry@@QAEHHQ6AHAAVCRPCParaPacker@@@Z@Z)

How to correct it?
 
V

Victor Bazarov

Allen said:
// 1. RPCMethodRegistry.h

typedef int (*RPCMethod)(CRPCParaPacker& packer);

class CRPCMethodEntry
{
public:
int id;
RPCMethod method;
};

class CRPCMethodRegistry
{
private:
CRPCMethodRegistry(void);
CRPCMethodRegistry(CRPCMethodRegistry const&); // No copy
constructor.
CRPCMethodRegistry& operator=(CRPCMethodRegistry const&); // No
assignment.

public:
static CRPCMethodRegistry& GetInstance(void);
virtual ~CRPCMethodRegistry(void);

public:
inline int RegisterMethod(const int nId, const RPCMethod pMethod);

Here you declared the 'RegisterMethod' member function. Where is
it defined? If the definition exists, the linker is unable to find
it anywhere. You need to tell it. How? Ask in the newsgroup for
your compiler/linker.
RPCMethod GetMethod(const int nId);

private:
static CRPCMethodEntry entries[256];
static CRPCMethodRegistry instance;
};

[...]

VS2005 tells a link error, cannot resolute external symbol public: int
__thiscall CRPCMethodRegistry::RegisterMethod(int,int (__cdecl*const)
(class CRPCParaPacker &))" (?
RegisterMethod@CRPCMethodRegistry@@QAEHHQ6AHAAVCRPCParaPacker@@@Z@Z)

How to correct it?

Define the function.

V
 
A

Allen

Allen said:
// 1. RPCMethodRegistry.h
typedef int (*RPCMethod)(CRPCParaPacker& packer);
class CRPCMethodEntry
{
public:
int id;
RPCMethod method;
};
class CRPCMethodRegistry
{
private:
CRPCMethodRegistry(void);
CRPCMethodRegistry(CRPCMethodRegistry const&); // No copy
constructor.
CRPCMethodRegistry& operator=(CRPCMethodRegistry const&); // No
assignment.
public:
static CRPCMethodRegistry& GetInstance(void);
virtual ~CRPCMethodRegistry(void);
public:
inline int RegisterMethod(const int nId, const RPCMethod pMethod);

Here you declared the 'RegisterMethod' member function. Where is
it defined? If the definition exists, the linker is unable to find
it anywhere. You need to tell it. How? Ask in the newsgroup for
your compiler/linker.
RPCMethod GetMethod(const int nId);
private:
static CRPCMethodEntry entries[256];
static CRPCMethodRegistry instance;
};

VS2005 tells a link error, cannot resolute external symbol public: int
__thiscall CRPCMethodRegistry::RegisterMethod(int,int (__cdecl*const)
(class CRPCParaPacker &))" (?
RegisterMethod@CRPCMethodRegistry@@QAEHHQ6AHAAVCRPCParaPacker@@@Z@Z)
How to correct it?

Define the function.

V

The difinition is coded in cpp files. Not given here.
I have found the answer.
Because I compile these classes into DLL, so class CRPCMethodRegistry
should be declared dll export.
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top