x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to write macros in c++?

Hello,

I was wondering how I can write macros like in blueprints but in c++?

Thanks in advance :) ~Stefan

Product Version: UE 4.22
Tags:
more ▼

asked Jul 15 '19 at 06:04 PM in C++ Programming

avatar image

Steferich
116 4 12 16

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Macros in C++ may sometimes be a bit tricky so be careful. You start it with #define directive.

#define macro-name replacement-text

Example:

#define PI 3.14159

Macros in C++ are used by preprocessor (stage before compilation and linking). In the example above it will simply replace all PI occurrences in code with 3.14159 number.

Macros can be more complex:

#define MIN(a,b) (((a)<(b)) ? a : b)

Example of usage:

std::cout << "The minimum is " << MIN(42, 8) << endl;

will result in:

The minimum is 8

Experienced C++ developers will suggest you to not use macros as long as possible. Functions and variables are most times a better choice. For example const float pi = 3.14159; is better than #define because it handles type and compiler can help you more when you will try to do something wrong with it.

More information:

https://en.cppreference.com/w/cpp/preprocessor

https://en.cppreference.com/w/cpp/preprocessor/replace

more ▼

answered Jul 15 '19 at 07:52 PM

avatar image

dptd
246 3 4 5

avatar image Steferich 13 hours ago

This is not what I meant. I'm trying to define a function in c++ that when used in blueprints can have more than 1 input/output. For example like the branch node in bps that have 2 outputs, "true" and "false".

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

UPROPERTY

link

Sample:

 UPROPERTY(EditAnywhere, BlueprintReadWrite)
 class UStaticMeshComponent* MyMeshComponent;




more ▼

answered Jul 15 '19 at 07:50 PM

avatar image

danielf94
173 5 8 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question