Skip to content

Using C API under C++: error: taking address of rvalue #918

Answered by SanderMertens
GrauBlitz asked this question in Q&A
Discussion options

You must be logged in to vote

The reason this happens is because ecs_set is part of a set of macro helpers that provide a sort of type safety for the C API, but they rely on features that are not available in C++ (such as taking the address of a temporary).

If you'd really like to use the C API from C++, consider using the "naked" C functions in the include/flecs.h file, like ecs_set_id:
https://github.com/SanderMertens/flecs/blob/master/include/flecs.h#L2529

It's a bit more typing, but you'll be using plain C functions:

// Initialize component to 0
EcsRest r = {};

// ecs_id(EcsRest) returns the name of the global variable that holds the component id for EcsRest
// A singleton is a component that's assigned to itself…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by GrauBlitz
Comment options

You must be logged in to vote
1 reply
@SanderMertens
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants