SFML community forums

Help => General => Topic started by: Yee7i on October 08, 2019, 03:02:25 pm

Title: Attempting to reference a deleted function
Post by: Yee7i on October 08, 2019, 03:02:25 pm
I've created a namespace for my game, and inside it a class with sf::Texture and sf::Sprite inside.

The code looks like this:

Classes.h

namespace at
{
        class Effect
        {
        public:

                int rotation = 0;

                std::string currentAnimation = "";

                sf::Vector2f position = sf::Vector2f(0.0f, 0.0f);

                sf::Texture texture;

                sf::Sprite sprite;

                thor::AnimationMap<sf::Sprite, std::string> aMap;

                thor::Animator<sf::Sprite, std::string> animator;
        };
}

Globals.h

extern at::Effect fireballGlow;

Globals.cpp

at::Effect fireballGlow;

Now I created an at::Effect in order to store a fireball glow inside. But when I try to build it VS throws
Error C2280 'at::Effect::Effect(void)': attempting to reference a deleted function
when I declare the glow in Globals.cpp.

I need an idea what's wrong here. I never call a missing function. I don't even have a void in that class, in fact.
Title: Re: Attempting to reference a deleted function
Post by: Laurent on October 08, 2019, 03:23:01 pm
It seems like thor::Animator has no default constructor, therefore the compiler cannot generate one for your Effect class.

Possible solution: define one yourself.

class Effect
{
public:

   Effect() : animator(aMap) {}

   ...
};
Title: Re: Attempting to reference a deleted function
Post by: Yee7i on October 08, 2019, 05:12:11 pm
Thanks for the quick reply Laurent

Now that I put it in, IntelliSense is telling me that
"at::Effect::Effect()" provides no initializer for:
reference member  "at::effect::sprite"
   

No matter if I put it after
sf::Sprite sprite
or before it
Title: Re: Attempting to reference a deleted function
Post by: Yee7i on October 08, 2019, 05:25:25 pm
Nevermind, I've just noticed I had a stray reference to Sprite I put accidentally. Instead of
sf::Sprite sprite;
I had
sf::Sprite& sprite;

The code works now that I've removed it. Thanks Laurent