Мне сказали, что я должен определить оператор присваивания для своего класса Bullet, однако у меня сложилось впечатление, что единственное время, когда вам действительно нужно реализовать правило трех, - это когда вы сами явно обрабатываете память, такую как класс указателя член.
Мне фактически говорят, что строка, которая пытается вызвать оператор =, - это std::vector<Bullet> bullets
в следующем коде. Я просто не понимаю, где вызывается оператор присваивания и почему он вызывается. Нигде я не делаю что-то вроде Bullet bullet1 = bullet2
;
РЕДАКТИРОВАТЬ - а также, почему не подходит оператор присваивания по умолчанию? У меня нет членов указателя в иерархии Bullet.
Спасибо за помощь.
#ifndef GUN_H
#define GUN_H
#include "gameObject.h"
#include "Bullet.h"
#include <vector>
class Mesh;
class Gun : public GameObject
{
private:
std::vector<Bullet> bullets; // this line right here
protected:
virtual void TriggerPulled() = 0;
public:
Gun(Mesh& mesh);
virtual ~Gun();
std::vector<Bullet>& Bullets();
};
#endif
это источник для того же файла:
#include "Gun.h"
#include "Mesh.h"
Gun::Gun(Mesh& mesh) : GameObject(mesh)
{
bullets = std::vector<Bullet>();
}
Gun::~Gun() {}
std::vector<Bullet>& Gun::Bullets()
{
return bullets;
}
это пуля:
#ifndef BULLET_H
#define BULLET_H
#include "BoundingSphere.h"
#include "helperMethods.h"
#include "GameObject.h"
class Bullet : public GameObject
{
private:
float velocity;
float distance;
D3DXVECTOR3 firedFrom;
BoundingSphere bSphere;
public:
Bullet(D3DXVECTOR3 position, D3DXVECTOR3 rotation, float velocity, D3DXCOLOR colour, Mesh& mesh);
~Bullet();
BoundingSphere& BulletSphere();
};
#endif
BoundingSphere:
#ifndef BOUNDING_SPHERE_H
#define BOUNDING_SPHERE_H
#include <d3d10.h>
#include <d3dx10.h>
class Ray;
class BoundingBox;
class BoundingSphere
{
private:
D3DXVECTOR3 centre;
float radius;
public:
BoundingSphere(D3DXVECTOR3 position, float radius);
BoundingSphere();
bool Intersects(BoundingSphere boundingSphere);
bool Intersects(BoundingBox boundingBox);
bool Intersects(Ray ray, D3DXVECTOR3& result);
// getters
const D3DXVECTOR3 Centre();
const float Radius();
// setters
void BoundingSphere::Centre(D3DXVECTOR3 centre);
};
#endif
геймобжекты:
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H
#include <d3d10.h>
#include <d3dx10.h>
class Mesh;
class GameObject
{
private:
D3DXVECTOR3 scale;
D3DXVECTOR3 rotation;
D3DXVECTOR3 position;
D3DXCOLOR colour;
D3DXMATRIX matFinal;
Mesh& mesh;
protected:
void Draw(D3DMATRIX matView, D3DMATRIX matProjection);
public:
GameObject(Mesh& mesh);
virtual ~GameObject();
//getters
const D3DXVECTOR3 Scale();
const D3DXVECTOR3 Rotation();
const D3DXVECTOR3 Position();
const D3DXCOLOR Colour();
//setters
void Scale(D3DXVECTOR3 scale);
void Rotation(D3DXVECTOR3 rotation);
void Position(D3DXVECTOR3 position);
void Colour(D3DXCOLOR colour);
};
#endif