error C2059: syntax error: '<tag>::*'
-
Hello, I'm trying to adapt some Microsoft code (member.cpp in Detours) for my case ( I just want to replace void CMember::Target(void) by QString QString::fromAscii(const char *str, int size): MS Code :
class CMember
{
public:
void Target(void);
};void CMember::Target(void)
{
printf(" CMember::Target! (this:%p)\n", this);
}//////////////////////////////////////////////////////////////// Detour Class.
//
class CDetour /* add ": public CMember" to enable access to member variables... */
{
public:
void Mine_Target(void);
static void (CDetour::* Real_Target)(void);// Class shouldn't have any member variables or virtual functions.
};
void CDetour::Mine_Target(void)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)();
}void (CDetour::* CDetour::Real_Target)(void) = (void (CDetour::*)(void))&CMember::Target;
My code :
class CDetour /* add ": public CMember" to enable access to member variables... */
{
public:
QString Mine_Target(const char *str, int size);
static QString (CDetour::* Real_Target)(const char *str, int size);// Class shouldn't have any member variables or virtual functions.
};
QString CDetour::Mine_Target(const char *str, int size)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)(str, size);
}QString (CDetour::* CDetour::Real_Target)(const char *str, int size) = (CDetour::*)(const char *str, int size)&QString::fromAscii;
But I get : error C2059: syntax error: '< tag >::*' for the last line Why ?! Thanks. Edit : If I do :
QString (CDetour::* CDetour::Real_Target)(const char *str, int size) = (QString(CDetour::*)(const char *str, int size))&QString::fromAscii;
I get : error C2440: 'type cast' : impossible to convert from 'QString (__cdecl *)(const char *,int)' into 'QString (__thiscall CDetour::* )(const char *,int)'
-
Hello, I'm trying to adapt some Microsoft code (member.cpp in Detours) for my case ( I just want to replace void CMember::Target(void) by QString QString::fromAscii(const char *str, int size): MS Code :
class CMember
{
public:
void Target(void);
};void CMember::Target(void)
{
printf(" CMember::Target! (this:%p)\n", this);
}//////////////////////////////////////////////////////////////// Detour Class.
//
class CDetour /* add ": public CMember" to enable access to member variables... */
{
public:
void Mine_Target(void);
static void (CDetour::* Real_Target)(void);// Class shouldn't have any member variables or virtual functions.
};
void CDetour::Mine_Target(void)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)();
}void (CDetour::* CDetour::Real_Target)(void) = (void (CDetour::*)(void))&CMember::Target;
My code :
class CDetour /* add ": public CMember" to enable access to member variables... */
{
public:
QString Mine_Target(const char *str, int size);
static QString (CDetour::* Real_Target)(const char *str, int size);// Class shouldn't have any member variables or virtual functions.
};
QString CDetour::Mine_Target(const char *str, int size)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)(str, size);
}QString (CDetour::* CDetour::Real_Target)(const char *str, int size) = (CDetour::*)(const char *str, int size)&QString::fromAscii;
But I get : error C2059: syntax error: '< tag >::*' for the last line Why ?! Thanks. Edit : If I do :
QString (CDetour::* CDetour::Real_Target)(const char *str, int size) = (QString(CDetour::*)(const char *str, int size))&QString::fromAscii;
I get : error C2440: 'type cast' : impossible to convert from 'QString (__cdecl *)(const char *,int)' into 'QString (__thiscall CDetour::* )(const char *,int)'
The first definition can't be correct. Regarding the second one, for me it looks like the QString::fromAscii isn't defined as a member method. Have you tried creating an own class like the CMember one and using this class' function in the function pointer? Once you get this working you can call QString::fromAscii directly from the inner function.
The good thing about pessimism is, that you are always either right or pleasently surprised.
-
The first definition can't be correct. Regarding the second one, for me it looks like the QString::fromAscii isn't defined as a member method. Have you tried creating an own class like the CMember one and using this class' function in the function pointer? Once you get this working you can call QString::fromAscii directly from the inner function.
The good thing about pessimism is, that you are always either right or pleasently surprised.
But QString::fromAscii is a Static Public Members from Qt : QString Class Reference I thought I just had to replace CMember by QString and Target by fromAscii from the MS sample...
-
Hello, I'm trying to adapt some Microsoft code (member.cpp in Detours) for my case ( I just want to replace void CMember::Target(void) by QString QString::fromAscii(const char *str, int size): MS Code :
class CMember
{
public:
void Target(void);
};void CMember::Target(void)
{
printf(" CMember::Target! (this:%p)\n", this);
}//////////////////////////////////////////////////////////////// Detour Class.
//
class CDetour /* add ": public CMember" to enable access to member variables... */
{
public:
void Mine_Target(void);
static void (CDetour::* Real_Target)(void);// Class shouldn't have any member variables or virtual functions.
};
void CDetour::Mine_Target(void)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)();
}void (CDetour::* CDetour::Real_Target)(void) = (void (CDetour::*)(void))&CMember::Target;
My code :
class CDetour /* add ": public CMember" to enable access to member variables... */
{
public:
QString Mine_Target(const char *str, int size);
static QString (CDetour::* Real_Target)(const char *str, int size);// Class shouldn't have any member variables or virtual functions.
};
QString CDetour::Mine_Target(const char *str, int size)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)(str, size);
}QString (CDetour::* CDetour::Real_Target)(const char *str, int size) = (CDetour::*)(const char *str, int size)&QString::fromAscii;
But I get : error C2059: syntax error: '< tag >::*' for the last line Why ?! Thanks. Edit : If I do :
QString (CDetour::* CDetour::Real_Target)(const char *str, int size) = (QString(CDetour::*)(const char *str, int size))&QString::fromAscii;
I get : error C2440: 'type cast' : impossible to convert from 'QString (__cdecl *)(const char *,int)' into 'QString (__thiscall CDetour::* )(const char *,int)'
You're trying to cast to
(CDetour::*)
, which isn't a valid type definition. It is only a part of a member function pointer definition and doesn't make sense without the parameter list and return type. Look at the last line in the MS code example:&CMember::Target
is the address of a member function pointer. You can only cast a member function pointer to a member function pointer of a differentsimilar type, in this case(void (CDetour::*)(void))
, which is a member function of the classDetour
(that is whatCDetour::*
means) with an empty parameter list (the(void)
bit) and a void return type (the precedingvoid
) The compiler error is based on the fact that the compiler doesn't recognize (CDetour::*) as part of a function pointer definition without the preceding return type, and there is no other valid interpretation. Your edit version looks better: the compiler does recognize the member function pointer cast correctly, it just doesn't want to accept that cast for some reason. One possible problem could be the calling convention being used: your class definition generated the member function using__thiscall
, whereas the QT function was defined as using__cdecl
. You may want to check your calling convention settings. [edit]fixed my statement about function pointer casts in light of what I said in the last paragraph[/edit]GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)