Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1047557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:19:11+00:00 2026-05-16T16:19:11+00:00

Can macro return an object? #define macro1 {obj1} Since macro is text substitution, could

  • 0

Can macro return an object?

#define macro1 {obj1}

Since macro is text substitution, could I use macro like macro1.function1()?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:19:12+00:00Added an answer on May 16, 2026 at 4:19 pm

    A macro never returns anything. A macro returns textual representation of code that will be pasted into the place of the program where it is used before compilation.

    Read about the C Preprocessor.

    So:

    #define macro1 {obj1}
    
    int main() {
      macro1
    }
    

    … will be compiled as if you wrote

    int main() {
      {obj1}
    }
    

    It’s just textual substitution, that can optionally take a parameter.


    If you’re using GCC you can take a look at what the program will look like after preprocessing, using the cpp tool:

    # cpp myprog.cpp myprog.cpp_out
    

    Generally mixing macro’s with objects is bad practice, use templates instead.


    One known usage of macro’s in terms of objects is using them to access singletons (however that isn’t such a nice idea in general):

    #define LOGGER Logger::getLogger()
    
    ...
    
    LOGGER->log("blah");
    

    You could also use the preprocessor to choose at compile time the object you want to use:

    #ifdef DEBUG
    #  define LOGGER DebugLogger
    #else
    #  define LOGGER Logger
    #end
    
    // assuming that DebugLogger and Logger are objects not types
    LOGGER.log("blah");
    

    … but the forementioned templates do that better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you do something like this with a macro in C ? #define SUPERMACRO(X,Y)
Does anyone know if and/or how you can define macro definitions in a gSoap
How can I use the ListView_GetBkImage macro: http://msdn.microsoft.com/en-us/library/bb761246(v=VS.85).aspx ... from a C#/WinForms application? I
Anyone can explain in details what the following macro does? #define write_XDATA(address,value) (((char *)0x010000)
Can anyone help me in the following question please? Define a macro which has
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want to have a macro dbtest that can be used like this: (dbtest
I was wondering if someone can explain this macro to me. #define Q_DECLARE_PRIVATE(Class) \
I would like to use create a object that contains regular expressions as the
Trying to create a macro which can be used for print debug messages when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.