Can i make two objects share the same members data

sorry , it's kind of a newbie question but is there any possible way to make twon objects ,for instance, with the same name member share the same data for the rest of the class members
here is the code to understand what i mean .
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>

using namespace std;

class weapon 
{
public :
string name;
int damage;

};
void betterdamage(weapon w1,weapon w2)
{
cout << w1.name << " damage is : " <<w1.damage<< endl;
cout << "Whereas " <<w2.name<< "'s damage is : " << w2.damage<< endl;
}

int main()
{
weapon weapon1;
weapon weapon2;
weapon AKM;
weapon AWM;

AKM.name = "AKM";
AWM.name = "AWM";

AKM.damage = 45;
AWM.damage = 120;

getline(cin, weapon1.name)
getline(cin, weapon2.name)

// at this moment , i want if the user types AKM to make the whole weapon1 members exactly the same as the AKM members previously input

betterdamage(weapon1,weapon2);
 
}

closed account (E0p9LyTq)
Static data members, and how to use them:

https://www.includehelp.com/cpp-tutorial/static-data-member-in-cpp-with-example.aspx
Topic archived. No new replies allowed.