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 3428472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:57:48+00:00 2026-05-18T06:57:48+00:00

How to define a macro (this Q is somehow related to this Q and

  • 0

How to define a macro (this Q is somehow related to this Q and CashCow’s answer) which will expand to a different integer if this macro is used on different line in code?
I would like to be able to type:

X<1> _0;
X<1> _1;

after such def. I would like _0 and _1 to be of different types.

  • 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-18T06:57:48+00:00Added an answer on May 18, 2026 at 6:57 am

    you can use something like this:

    #define var(T,...) T<__VA_ARGS__,__LINE__> 
    

    or if your only doing this for one know type:

    #define var(x) T<(x),__LINE__> 
    

    I suggest using __COUNTER__ instead of __LINE__ however, it allows the type to be globaly
    unique, not just unique to the line.

    EDIT: reread the question, what exactly do you mean by “different integer”? as in a different type or different initialization value?

    template<typename T = int, const T nValue> class Integer
    {
        T Value;
        Integer() : Value(nValue)
        {
        }
    
        operator T()
        {
            return Value;
        }
    };
    
    #define VI(x) Integer<__COUNTER__> x
    

    or (This seems to be the one you want)

    #define I(x) int x(__COUNTER__)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having trouble trying to define this function-like macro, which takes 4 vector magnitudes
I was browsing some code and I came across this macro definition #define D(x)
Consider this macro: #define MAKE_TEMPLATE(...) template <typename T, __VA_ARGS__ > When used with zero
If you have a macro like this in C: #define SLICE_VERSION 20110614 How to
Can you do something like this with a macro in C ? #define SUPERMACRO(X,Y)
In object type macro it is possible below, #define str this is a string
I want to define a macro that can be invoked in different places (at
Possible Duplicate: Problem with Macros Hi all I have defined this macro: #define SQ(a)
I have macro like this: #define error_exit(format, ...) \ error_at_line(EXIT_FAILURE, 0, __FILE__, __LINE__, format,
Is this macro safe or should I make sure alloca never returns NULL? #define

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.