Pointer to class member function
-
Hi, Maybe today isn't my best day ;) but could anyone tell me what is wrong with this snippet ?
class CTest
{
public:
CTest()
{
(*(this)).lpFunc = &CTest::Write;
}
long Write(DWORD dwInfo)
{
...
}
long (*lpFunc)(DWORD);
}I've got error C2440:
'=' : cannot convert from 'long (__thiscall CTest::* )(DWORD)' to 'long (__cdecl *)(DWORD)'
and when I change line: (*(this)).lpFunc = &CTest::Write; to
(CTest::*lpFunc) = &CTest::Write;
I've got another error code:
error C2059: syntax error : '<tag>::*'
Generally I want to point on lpFunc a pointer to Write fuction but within class (I don't want to any globals). ----------- Mila -- modified at 3:15 Wednesday 28th June, 2006
-
Hi, Maybe today isn't my best day ;) but could anyone tell me what is wrong with this snippet ?
class CTest
{
public:
CTest()
{
(*(this)).lpFunc = &CTest::Write;
}
long Write(DWORD dwInfo)
{
...
}
long (*lpFunc)(DWORD);
}I've got error C2440:
'=' : cannot convert from 'long (__thiscall CTest::* )(DWORD)' to 'long (__cdecl *)(DWORD)'
and when I change line: (*(this)).lpFunc = &CTest::Write; to
(CTest::*lpFunc) = &CTest::Write;
I've got another error code:
error C2059: syntax error : '<tag>::*'
Generally I want to point on lpFunc a pointer to Write fuction but within class (I don't want to any globals). ----------- Mila -- modified at 3:15 Wednesday 28th June, 2006
Mila025 wrote:
'=' : cannot convert from 'long (__thiscall CTest::* )(DWORD)' to 'long (__cdecl *)(DWORD)'
notice the calling convention of the two parts of your operator = reported by the compiler. you function Write has to be either static or global. the fact is that being a class member function implicitely adds it the this pointer parameter...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Hi, Maybe today isn't my best day ;) but could anyone tell me what is wrong with this snippet ?
class CTest
{
public:
CTest()
{
(*(this)).lpFunc = &CTest::Write;
}
long Write(DWORD dwInfo)
{
...
}
long (*lpFunc)(DWORD);
}I've got error C2440:
'=' : cannot convert from 'long (__thiscall CTest::* )(DWORD)' to 'long (__cdecl *)(DWORD)'
and when I change line: (*(this)).lpFunc = &CTest::Write; to
(CTest::*lpFunc) = &CTest::Write;
I've got another error code:
error C2059: syntax error : '<tag>::*'
Generally I want to point on lpFunc a pointer to Write fuction but within class (I don't want to any globals). ----------- Mila -- modified at 3:15 Wednesday 28th June, 2006
-
Hi, Maybe today isn't my best day ;) but could anyone tell me what is wrong with this snippet ?
class CTest
{
public:
CTest()
{
(*(this)).lpFunc = &CTest::Write;
}
long Write(DWORD dwInfo)
{
...
}
long (*lpFunc)(DWORD);
}I've got error C2440:
'=' : cannot convert from 'long (__thiscall CTest::* )(DWORD)' to 'long (__cdecl *)(DWORD)'
and when I change line: (*(this)).lpFunc = &CTest::Write; to
(CTest::*lpFunc) = &CTest::Write;
I've got another error code:
error C2059: syntax error : '<tag>::*'
Generally I want to point on lpFunc a pointer to Write fuction but within class (I don't want to any globals). ----------- Mila -- modified at 3:15 Wednesday 28th June, 2006
That's not how you declare a member function pointer.
class CTest
{
public:
CTest()
{
lpFunc = &CTest::Write;
}
long Write(DWORD dwInfo)
{
...
}
long (CTest::*lpFunc)(DWORD); // declaration for member function pointer
}; -
Mila025 wrote:
'=' : cannot convert from 'long (__thiscall CTest::* )(DWORD)' to 'long (__cdecl *)(DWORD)'
notice the calling convention of the two parts of your operator = reported by the compiler. you function Write has to be either static or global. the fact is that being a class member function implicitely adds it the this pointer parameter...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]