C++: Macros

K

Kevin Goodsell

Web said:
Hi,

What are Macros in C++?

A macro is only slightly better than the "find and replace" function of
most text editors. If I define a macro like this:

#define SOME_MACRO some text

Then every occurrence of SOME_MACRO in the source that follows will be
replaced with "some text" (without the quote marks). There are
exceptions, though. If the code that follows contains this:

cout << "SOME_MACRO" << endl;

The substitution does not occur in this case because the SOME_MACRO is
inside a string literal.

You can also have parameterized macros that act somewhat like inlined
functions.

Use of macros is discouraged in C++. They are dangerous and rarely
necessary.

You should be able to read all about this in your C++ book. Why didn't
you? I guarantee you that you cannot learn C++ from a newsgroup.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top