Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Attempting to reference a deleted function  (Read 1642 times)

0 Members and 1 Guest are viewing this topic.

Yee7i

  • Newbie
  • *
  • Posts: 13
    • View Profile
Attempting to reference a deleted function
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Attempting to reference a deleted function
« Reply #1 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) {}

   ...
};
Laurent Gomila - SFML developer

Yee7i

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Attempting to reference a deleted function
« Reply #2 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

Yee7i

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Attempting to reference a deleted function
« Reply #3 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

 

anything