I have this class
class HumanA
{
public:
HumanA(std::string name, Weapon weapon);
~HumanA(void);
inline void attack(void)
{
std::cout << _name << " attacks with his " << _weapon.getType();
}
private:
std::string _name;
Weapon &_weapon;
};
and this constructor
HumanA::HumanA(std::string name, Weapon weapon) : _name(ft::strcapitalize(name)), _weapon(weapon)
{
}
and I get this error at compilation
HumanA.cpp:15:91: error: binding reference member '_weapon' to stack allocated
parameter 'weapon' [-Werror,-Wdangling-field]
...name, Weapon weapon) : _name(ft::strcapitalize(name)), _weapon(weapon)
^~~~~~
./HumanA.hpp:35:12: note: reference member declared here
Weapon &_weapon;
^
1 error generated.
isn't it possible to have a reference to stack allocated memory? This error seems weird to me.