C++ define function [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I would like to ask if there is a way to use define to create a function in C++ like that:
#define RequiredDamage(%1) ( (%1+1)*500 )
Could somebody help me to find better understanding of how #define actually works. What's the actual syntax to actually create a function like that, where could it be applied, is it a good idea to use it and why would I prefer it over a normal function?
Thanks in advance!

Yes, you need to provide an argument in your macro definition:
#define RequiredDamage(x) ( (x+1)*500 )

Related

DIfference in function signatures between C++11 and C++14 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want access to a complete list of function signatures that were present in C++11 but removed in C++14 and also list of function signatures that were added in C++14.
I do not want to scrape the standard to look for the difference.
Is there a faster way to do it?
Thanks everyone for the help.
I have stumbled upon a link that clearly highights the difference between the two versions and is proving to be very informative to me.
I am posting it here so that if anyone has the same question as mine, they can refer here.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1319r0.html

Is there any reason why I shouldn't use function objects instead of functions? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I've been trying to teach myself how to program by working through the book Programming: Principles and Practice Using C++ by Bjarne Stroustrup and I recently learned about function objects, the way it was described in the book it seems like I shouldn't ever use regular functions and should always use function objects instead, even if I don't need a state for the function. I couldn't find anything on this site or using goolge to check if I should be using them that way or not. Is it wrong? Are there any down sides to using them? Thank you in advance for helping.

How likely is istream::ungetc() to work with a stringbuf (as used in stringstream)? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've tried searching for the answer, but nothing mentions stringstream specifically. I would guess that it would always work and you can always go back as far as the beginning of the underlying string.
Am I right?
How likely is istream::ungetc() to work with a stringbuf (as used in stringstream)?
Well, never.
There's no such thing like istream::ungetc() defined from the standard.
You can use either
int std::ungetc( int ch, std::FILE *stream )
or
std::basic_istream& std::basic_istream::unget()

How To Set Up Timer In C++? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm new to C++ and currently I'm using Code::Blocks to run my code. So, I wonder if i can set up timer until a code is executed because i need timer to make my program looks better. Any answers is accepted ^^
I wrote a timer class long ago. You can find the complete code on Github here: timer
It is a complete example with Makefile as well.
Note: You will need the ability to compile C++11.
You can create a class for this purpose. In constructor and destructor get the current time. You only need to subtracts them to get the elapse time of each functions including main.
http://en.cppreference.com/w/cpp/chrono

How to make a MATLAB function to be run in html? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I've developed a MATLAB code that I think it is useful to be used by researchers. How can I embed it in a website to be used free?
It gets two integers and return a set of integers
Also it is possible to convert it to c++, If it helps.
Thanks
Submit your m-file(s) to Matlab Central File Exchange, this is the perfect place for it.