Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error C2059: syntax error: '<tag>::*'

error C2059: syntax error: '<tag>::*'

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jeff6
    wrote on last edited by
    #1

    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)'

    F S 2 Replies Last reply
    0
    • J jeff6

      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)'

      F Offline
      F Offline
      Freak30
      wrote on last edited by
      #2

      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.

      J 1 Reply Last reply
      0
      • F Freak30

        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.

        J Offline
        J Offline
        jeff6
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • J jeff6

          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)'

          S Offline
          S Offline
          Stefan_Lang
          wrote on last edited by
          #4

          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 class Detour (that is what CDetour::* means) with an empty parameter list (the (void) bit) and a void return type (the preceding void) 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)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups