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. #define syntax for create a class instance

#define syntax for create a class instance

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 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.
  • H Offline
    H Offline
    hyling
    wrote on last edited by
    #1

    Hi, Is it possible to create a macro that would create an instance of a class? I'm trying this but the compiler won't accept it: #define Logger() (MyLogger tempLogger(__FUNCTION__, __FILE__, __LINE__)) Thanks Hua-Ying

    T N 2 Replies Last reply
    0
    • H hyling

      Hi, Is it possible to create a macro that would create an instance of a class? I'm trying this but the compiler won't accept it: #define Logger() (MyLogger tempLogger(__FUNCTION__, __FILE__, __LINE__)) Thanks Hua-Ying

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      and what does the compiler say ?


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      H 1 Reply Last reply
      0
      • H hyling

        Hi, Is it possible to create a macro that would create an instance of a class? I'm trying this but the compiler won't accept it: #define Logger() (MyLogger tempLogger(__FUNCTION__, __FILE__, __LINE__)) Thanks Hua-Ying

        N Offline
        N Offline
        Neagoe Gabriel
        wrote on last edited by
        #3

        class MyLogger { MyLogger( char*, char*, char*) { } }; #define Logger() (MyLogger tempLogger(__FUNCTION__, __FILE__, __LINE__)) no error on visual c++ 6.0... NG

        H 1 Reply Last reply
        0
        • T toxcct

          and what does the compiler say ?


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          H Offline
          H Offline
          hyling
          wrote on last edited by
          #4

          error C2059: syntax error : ')' error C2146: syntax error : missing ')' before identifier 'tempLogger' error C3861: 'tempLogger': identifier not found, even with argument-dependent lookup

          1 Reply Last reply
          0
          • N Neagoe Gabriel

            class MyLogger { MyLogger( char*, char*, char*) { } }; #define Logger() (MyLogger tempLogger(__FUNCTION__, __FILE__, __LINE__)) no error on visual c++ 6.0... NG

            H Offline
            H Offline
            hyling
            wrote on last edited by
            #5

            The syntax error only occurs when I try to use the macro. The errors are: error C2059: syntax error : ')' error C2146: syntax error : missing ')' before identifier 'tempLogger' error C3861: 'tempLogger': identifier not found, even with argument-dependent lookup Hua-Ying

            A 1 Reply Last reply
            0
            • H hyling

              The syntax error only occurs when I try to use the macro. The errors are: error C2059: syntax error : ')' error C2146: syntax error : missing ')' before identifier 'tempLogger' error C3861: 'tempLogger': identifier not found, even with argument-dependent lookup Hua-Ying

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              #include using namespace std; #define Logger() MyLogger tempLogger(__FUNCTION__, __FILE__, __LINE__) class MyLogger { public: MyLogger(char *pFunction, char *pFile, long Line) { cout<

              H 1 Reply Last reply
              0
              • A Anonymous

                #include using namespace std; #define Logger() MyLogger tempLogger(__FUNCTION__, __FILE__, __LINE__) class MyLogger { public: MyLogger(char *pFunction, char *pFile, long Line) { cout<

                H Offline
                H Offline
                hyling
                wrote on last edited by
                #7

                Thanks that really does work! I've always though that argument in a #define were separated by spaces so that it would see 3 arguments there. I guess I was wrong!

                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