0

I'm having a little bit of a hard time explaning the problem, so here's a simple rundown of my code:

Imagine I have a class called 'character'

#include "myEnums"
#include "weapon"

character {
 protected:
    string characterName;
    weapon* myWeapon;
 public:
    string getCharacterName();
    void setCharacterName( string );
    string getMyWeapon();
    void setMyWeapon();
}

Then within 'setMyWeapon' I use this simplified code.

void character::setMyWeapon() {
    this->myWeapon = new weapon("longsword");
    //this->myWeapon = new weapon(myEnums::LONGSWORD); //Ideally this
}

string getMyWeapon() {
    return this->myWeapon.tostring();
}

But when I type the '.' for 'myWeapon' there's no members, anyone know whatup? Assume 'tostring' is defined in 'weapon.h'...

RaenirSalazar
  • 556
  • 1
  • 7
  • 20

1 Answers1

1

Since myWeapon is a pointer, you need to dereference it to access the pointee's members:

myWeapon->tostring()
//     ^^^^
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084