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

  • Home
  • SEARCH
  • 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 4602402
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:58:44+00:00 2026-05-21T23:58:44+00:00

I have a bunch of classes such as the following, class SomeClass : public

  • 0

I have a bunch of classes such as the following,


class SomeClass : public Function{
public:

   ref call(ref args){
    // do & return stuff
   }

   int getType(){return TYPE;}
   ref toString(){ return "SomeClass";}
};

I got like 50 of these and the only thing that is different is the body of the call function. Is it possible to have a macro that will take a name and a body and replace “SomeClass” with name and insert body into call function?

  • 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-21T23:58:45+00:00Added an answer on May 21, 2026 at 11:58 pm

    Sure. Expanding the body of the call member function is a bit easier if you have a compiler that supports variadic macros. While I’ve used Boost.Preprocessor’s stringize macro, it is trivial to write your own.

    #define DEFINE_CLASS(name, parenthesized_call_body)                 \
        class name : public Function {                                  \
            ref call (ref args) {                                       \
                DEFINE_CLASS_CALL_BODY parenthesized_call_body          \
            }                                                           \
            int getType() { return TYPE; }                              \
            const char* toString() { return BOOST_PP_STRINGIZE(name); } \
        };
    
    #define DEFINE_CLASS_CALL_BODY(...) __VA_ARGS__
    

    Used as:

    DEFINE_CLASS(SomeClass, (return ref()))
    

    The call body needs to be parenthesized so that any commas present in the body are not treated as macro argument separators. Alternatively, you could just declare the call function in the class definition and then define that function separately.

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

Sidebar

Related Questions

Let's say I have a bunch of classes that look something like... class Foo{
I have a bunch of classes extending an abstract Base class. Each subclass takes
I have a bunch of classes which implement geometric objects based on vertices, such
I have a bunch of classes of the following format, located in the various
I have a bunch of classes in a C# class library that I bought
I have a bunch of third-party Java classes that use different property names for
imagine I have a bunch of C++ related classes (all extending the same base
After I have created a serious bunch of classes (with initialize methods), I am
I have a web application that contains a bunch of classes in the App_Code
In my program, I've got a bunch of classes that will only ever have

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.