Xcodecopy asignment operator is implictly deleted when trying to delete from vector?

So I'm trying to write a clone of Space invader using SFML and everything was going fine until I tried to delete from a couple of vectors, now I'm getting an error telling me that the assignment operator has been implicitly deleted. I've tried lots of different things but can't seem to get rid of this error. As I understand the assignment operator is deleted when you declare another user created one which I haven't done.. That I know of. I've tried searching all over for how to fix this but everything I've found doesn't help. How would one go about fixing this?

This is where I'm trying to remove from the vector

1
2
3
4
5
6
7
8
9
10
void Game_Screen::shot_collision(int index){
	for (int i = 0; i < shield.size(); i++){
		if (shots[index].getX() == shield[i].getX()){
			if (shots[index].getY() == shield[i].getY() + 1 || shots[index].getY() == shield[i].getY()){
				shots.erase(shots.begin() + index);
				shield.erase(shield.begin() + i);
			}
		}
	}
}


Here's Shot.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef Shield_hpp
#define Shield_hpp

class Shot{
private:
	const int SPEED = 4;
	float x, y;
	int ydir;
	
public:
	//Empty constructor
	Shot();
	
	//Constuctor with parameters
	Shot(float x, float y, bool invader);
	~Shot();
	
	void move_shot();
	
	//Getters
	float getX();
	float getY();
};

#endif /* Shot_hpp */ 


Here's Shield.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef Shield_hpp
#define Shield_hpp

class Shield{
private:
	float x, y;
	const float SIZE = 1;
	
	
public:
	Shield();
	Shield(float x, float y);
	~Shield();
	
	//Getters
	float getX();
	float getY();
	float getSize();
	
	//Setters
	void setX(int x);
	void setY(int y);
};

#endif /* Shield_hpp */ 


I saw on here somewhere an example where someone used something along the lines of
1
2
Shield& operator=(const Shield&) { return *this ; }
Shield& operator=(Shield&&) { return *this ; }


Which just caused more errors for me. I saw on stack overflow someone said to just use a std::list instead which wouldn't suit my needs for me or a std::set which also seems like it just wouldn't suit my needs.
Last edited on
this is due to const non-static member variables.
You should declare them static.
static const int SPEED = 4;

static const int SIZE = 1;
Yes that's fixed it! Thanks a ton mate.
I am curious though, why exactly would not having my constants set to static make the copy assignment operators of both the classes be implicitly deleted?
why exactly would not having my constants set to static make the copy assignment operators of both the classes be implicitly deleted?
Because you cannot copy to a const member.
Topic archived. No new replies allowed.