Overloades member function

K

Krish

Hi There,

I am having problem when I compile a code which I create to test a
source file. The errors are :
error C2144: syntax error : 'void' should be preceded by ';'
error C2511: 'void CNewServiceApp::function(SER,DWORD,LPVOID)' :
overloaded member function not found in 'CNewServiceApp'

Can someone help me to solve this?
Thanks,
Krish

HeaderFile
class CNewServiceApp : public CWinApp
{
public:
CNewServiceApp();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CNewServiceApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL

// Implementation
//func(int);
//func(this);

static DWORD CALLBACK function(CService*, DWORD, LPVOID);
DWORD function(CService*, DWORD);

LPVOID arg;

//{{AFX_MSG(CNewServiceApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CPP file:

BOOL CNewServiceApp::InitInstance()
{
AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

arg = this;

MyService = new CService("NewService",function, this );


return FALSE;

}



typedef CService SER
void CNewServiceApp::function(SER A, DWORD na, LPVOID arg)
{
CNewServiceApp *pCNewServiceApp;

if (arg == NULL)
{
return FALSE;
}

pCNewServiceApp = (CNewServiceApp*)arg;

return pCNewServiceApp ->function(A, arg);

}
 
D

David Hilsee

Krish said:
Hi There,

I am having problem when I compile a code which I create to test a
source file. The errors are :
error C2144: syntax error : 'void' should be preceded by ';'
error C2511: 'void CNewServiceApp::function(SER,DWORD,LPVOID)' :
overloaded member function not found in 'CNewServiceApp'

Can someone help me to solve this?
Thanks,
Krish

HeaderFile
class CNewServiceApp : public CWinApp
{
public:
CNewServiceApp();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CNewServiceApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL

// Implementation
//func(int);
//func(this);

static DWORD CALLBACK function(CService*, DWORD, LPVOID);
DWORD function(CService*, DWORD);

LPVOID arg;

//{{AFX_MSG(CNewServiceApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CPP file:

BOOL CNewServiceApp::InitInstance()
{
AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

arg = this;

MyService = new CService("NewService",function, this );


return FALSE;

}



typedef CService SER
void CNewServiceApp::function(SER A, DWORD na, LPVOID arg)
{
CNewServiceApp *pCNewServiceApp;

if (arg == NULL)
{
return FALSE;
}

pCNewServiceApp = (CNewServiceApp*)arg;

return pCNewServiceApp ->function(A, arg);

}

I'm going to try to ignore all of the unexplained stuff that resembles MFC
and answer your questions as they pertain to the C++ language.

First of all, the line reading

typedef CService SER

needs a semicolon

typedef CService SER;

And, AFAICT, you were trying to declare and define a member function of
CNewServiceApp (CNewServiceApp::function) that takes a CService*, so
wouldn't you use

void CNewServiceApp::function(SER * A, DWORD na, LPVOID arg)

in the definition? After all, SER is a typedef for CService, not a pointer
to a CService. If I were you, I would move the typedef so I could use it in
both the declaration and the definition, but that's entirely up to you.
 
J

John Harrison

David Hilsee said:
First of all, the line reading

typedef CService SER

needs a semicolon

typedef CService SER;

And, AFAICT, you were trying to declare and define a member function of
CNewServiceApp (CNewServiceApp::function) that takes a CService*, so
wouldn't you use

void CNewServiceApp::function(SER * A, DWORD na, LPVOID arg)

in the definition? After all, SER is a typedef for CService, not a
pointer
to a CService. If I were you, I would move the typedef so I could use it
in
both the declaration and the definition, but that's entirely up to you.

If I were the OP I'd just remove the typedef entirely. After all what is the
point of

typedef CService SER;

Why not just use CService throughout and avoid confusing everybody
(including yourself).

john
 
K

Krish

Thanks for you replies.

I have a question, if I have a global function that pointed to class
or object, then how do I pass arguments to that function.
I have CService *MyService; in my cpp
and in my header, i have
static DWORD CALLBACK function(CService*, DWORD, LPVOID);
DWORD func(CService*, DWORD);

then how do i pass argument for that pointer.
CNewServiceApp::function(-------, DWORD R, LPVOID arg);
what should I put in ----- above.

Krish
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top