Hello there, I'm steadilly progressing through some C++ Begineers textbooks, quite near to the end of them now, and I'm having a bit of difficulty with an object linking an object.
I've posted a sample code, which is just a watered down version of my larger project, but it is just the one error, I know the problem, but I'm unsure of how to go about it.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <string>
using namespace std;
class Armour
{
public:
Armour(int strength);
int GetStrength() const;
private:
int m_Strength;
};
Armour::Armour(int strength)
{
m_Strength = strength;
}
int Armour::GetStrength() const
{
return m_Strength;
}
class Dwarf
{
public:
Dwarf(int strength);
int GetStrength() const;
void SetEquip(Armour& equip);
private:
int m_Strength;
Armour* chest;
};
Dwarf::Dwarf(int strength)
{
m_Strength = strength + chest->GetStrength();
}
int Dwarf::GetStrength() const
{
return m_Strength;
}
void Dwarf::SetEquip(Armour& equip)
{
chest = equip;
}
int main()
{
Dwarf dwarfOne(10);
Armour goldHauberk(10);
cin.get();
cin.ignore();
return 0;
}
| |
The SetEquip function, I realise I am handling the pointer in the wrong way.
cannot convert `Armour' to `Armour*' in assignment |
Could someone explain the correct usage of what I am trying to achieve.
I believe all the information someone with more experience needs is all there, however feel free to ask for further details, and of course, thank you in advance! :)