godotengine / godotengine/godot-cpp

error: returning reference to local temporary object

Open
#785 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

I'm trying to connect the `animation_finished` event as follow:

```
void Hero::_register_methods() {
//....
register_method("_ready", &Hero::_ready);
register_method("AnimationFinished", &Hero::AnimationFinished);
}

void Hero::_ready() {
m_anim_player = get_node("Body/Skeleton/AnimationPlayer");

m_anim_player->connect("animation_finished", this, "AnimationFinished");
}

void Hero::AnimationFinished(const String& animation) {

}
```

but I get this error:

```
build/darwin/_deps/godot-cpp-src/include/core/Godot.hpp:163:10: error: returning reference to local temporary object [-Werror,-Wreturn-stack-address]
return a;
```

```
template
struct _ArgCast {
static T _arg_cast(Variant a) {
>>> return a;
}
};
```

however if I made the method accept normal String not by reference , it works fine
` void Hero::AnimationFinished( String animation) {}`

but isn't that unnecessary copying the parameters on each call?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.