Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6935067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:03:13+00:00 2026-05-27T12:03:13+00:00

I am told I have to define an assignment operator for my Bullet class,

  • 0

I am told I have to define an assignment operator for my Bullet class, however I was under the impression that the only time you really needed to implement the rule of three was when you explicitly handle memory yourself, such as a pointer class member.

I am actually told that the line that is attempting to invoke the operator= is std::vector<Bullet> bullets in the following code. I just don’t understand where the assignment operator is being called, and why it’s being called. Nowhere am I doing something like Bullet bullet1 = bullet2;

EDIT – and also, why isn’t the default assignment operator suitable? I have no pointer members anywhere in Bullet’s hierarchy.

Thanks for the help.

#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

this is the source for the same file:

#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;
}

this is bullet:

#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

gameObject:

#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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:03:13+00:00Added an answer on May 27, 2026 at 12:03 pm

    In the source you have:

    bullets = std::vector<Bullet>();
    

    The default = operator won’t work because GameObject has a reference member mesh which can’t be assigned to. (It’s almost like a pointer. It holds an address to an actual class or structure)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a (hopefully) really simple question - I have been told recently that
Well, I was told that I have to create a money class that accepts
I have been told that there is a performance difference between the following code
We have been told that we have to use a piece of software called
I am building a web application and have been told that using object oriented
I'm confused about this. Most of us have been told that there isn't any
I have previously been told that I should always use Randomize() before I use
Here is the code that I have so far to define the icon: icon_bg
I have written an application that allows a user to define a query, run
I'm trying to create a C++ dynamic library that won't have a class. I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.