Jump to content
  • Advertisement
Sign in to follow this  
jblevins1991

error code on objects in c++

This topic is 2498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

There are my theoretical classes for my question:

class Warrior
{
public:
int m_hp;

};

here is the item.h code

#include "Warrior.h"

class healingitems
{
int m_healhp;

void Heal();
};

here is the item.cpp file's code

#include "item.h"

void healingitems::Heal()
{
warrior.m_hp =+ m_heal;
}

The Heal() function takes the warriors hp stat and atdds m_heal. so lets say that i am low on health and i want to use a potion and the potion in my game heals 30 hp (that is this functions purpose).

My error is "a non static member must be relative to a specific object". How would i make it to where it heals an objects hp without being specific?

Share this post


Link to post
Share on other sites
Advertisement

Try healingitems::Heal(Warrior warrior).

That would make a copy of the Warrior object. You probably actually want a reference (Warrior & warrior)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!