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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:50:51+00:00 2026-06-09T10:50:51+00:00

i got the following code: header file: #define html(…) anyHtml(__VA_ARGS__, NULL); const char* Html::anyHtml(const

  • 0

i got the following code:

header file:

  #define html(...) anyHtml(__VA_ARGS__, NULL);
  const char* Html::anyHtml(const char* arg, ...);
  #define body(cssClass, ...) anyBody(cssClass, __VA_ARGS__, NULL);
  const char* Html::anyBody(const char* cssClass, const char* arg, ...);

cpp file:

const char* Html::anyHtml(const char* arg, ...) {
string temp = initOpen + tagToString.at(HTML) + end + lf + lf;
va_list arguments;
for (va_start(arguments, arg); arg != NULL; arg = va_arg(arguments, const char*)) {
temp += arg + lf;
}
va_end(arguments);
temp += deOpen + tagToString.at(HTML) + end + lf;
string *returnThis = new string(temp);
return (*returnThis).c_str();
}

const char* Html::body(const char* cssClass, const char* arg, ...) {
string temp = initOpen + tagToString.at(BODY) + " class=\"" + cssClass + "\"" + end + lf + lf;
va_list arguments;
for (va_start(arguments, arg); arg != NULL; arg = va_arg(arguments, const char*)) {
temp += arg + lf +lf;
}
va_end(arguments);
temp += deOpen + tagToString.at(BODY) + end + lf;
string *returnThis = new string(temp);
return (*returnThis).c_str();
}

main file:

Html *html = new Html();

cout << html -> html("test","test","test");
cout << html -> body("thisClass","test","test");

works fine!!

BUT THIS:

Html *html = new Html();

cout << html -> html(
    "hello",
    html -> body("thisClass","content")
    );

dont work..
if i outcomment the macro for anyBody in the header file

//#define body(cssClass, ...) anyBody(cssClass, __VA_ARGS__, NULL);

it is possible like this:

Html *html = new Html();

cout << html -> html(
    "hello",
    html -> body("thisClass","content",NULL)
    );

now my questions:

is it possible to nest some macros like

#define body(cssClass, ...) anyBody(cssClass, __VA_ARGS__, NULL);

among themselves ?

i´ve read that the whole “variable argument count” thing is still not really designed in cpp today?

if you take a look at the functions anyHtml() and anyBody(). is this a “good” solution for this issue or is it some kind of a dirty newbe hack? i´m still new to cpp coming along with perl and java mostly.. for this i want to get some feedback to get further with it..

now.. enough 🙂

your welcome to tell me what u want to say.. 🙂

—- EDIT

ok i´m sorry..

Html *html = new Html();

cout << html -> html(
    "hello",
    html -> body("thisClass","content")
    );

the output should be

<html>
hello
<body class="thisClass">
content
</body>
</html>

but it gives

C2143 Syntax Error missing ')' before ';'
C2143 Syntax Error missing ')' before ';'
C2059 Syntax Error: ')'

if i use both

#define html(...) anyHtml(__VA_ARGS__, NULL);
#define body(cssClass, ...) anyBody(cssClass, __VA_ARGS__, NULL);

if i make

cout << html -> html("hello","test");
cout << html -> body("thisClass","content");

these errors not appearing..

without this macros i have to type this:

 cout << html -> html(
    "hello",
    html -> body("thisClass","content",NULL)
    );

very special i know.. 🙁

— EDIT

thanks for fixing my issue!

the semicolon in the macro definition solved the nesting problem…

what about the functions anyHtml() and body()…

is it correct with using the

string temp = ...

and casting it after the string operations?

or is it dirty?

  • 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-06-09T10:50:52+00:00Added an answer on June 9, 2026 at 10:50 am

    You have extraneous semicolon’s in your macros. Remove them:

    #define html(...) anyHtml(__VA_ARGS__, NULL)
    #define body(cssClass, ...) anyBody(cssClass, __VA_ARGS__, NULL)
    

    If you don’t remove them, you end up with syntax errors, because the expansion turns into something like this:

    cout << html -> anyHtml(
        "hello",
        html -> anyBody("thisClass", "content", NULL);, NULL);;
    

    Edit: You asked:

    Is it correct with using the string temp = ... and casting it after the string operations? or is it dirty?

    You are not casting temp, but creating a copy of it in dynamically allocated memory. Although this allows you to pass back a valid C string, it is creating a memory leak, since you will not be able to call delete on the object you created.

    You can just change your routines to return std::string, and then you can return temp directly without without needing dynamic allocation.

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

Sidebar

Related Questions

I got the following code: char buffer[2047]; int charsRead; do { if(fscanf(file, %2047[^\n]%n%*c, buffer,
I got the following code, which converts a char[] to a byte[]: char[] cPwd
I got the following code inside an NSTimer selector: [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2.0];
I've got the following setup. RectangleT class defined in a header file in a
I've got the following code: vlib_stage_decoding_config_t Decoder::CfgTransform(const DecodingConfig config) { vlib_stage_decoding_config_t cfg; return cfg;
I got this problem when I add this following script in my header.php file.
I got following code in an XHTML-document and every browser saysit is malformed :(
I got following code from net and it looks everything is proper but i'm
I've got following code in my AsyncTask. The only thing I want the AsyncTask
I got the following code : <script type=text/javascript> jQuery(document).ready(function(){ var Opened = false; jQuery('.expend-schedule').click(function(e){

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.