[edited to try and eliminate word wrapping in code]
I was simply wondering if this was a mal-formed class header:
#ifndef _items_h_
#define _items_h_
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Item
{
public:
Item( float weight = 0,\
bool set_can_equip = false,\
bool set_can_attack = false,\
bool set_can_defend = false,\
bool set_can_drink= false,\
bool set_can_eat = false,\
bool set_can_use = false,\
bool set_is_consumab le = false,\
bool set_is_magical = false );
//Below are the set and get functions for
//all variables in this class
void set_weight( float weight )
{ item_weight = weight; }
float get_weight()
{ return item_weight; }
void set_can_equip( bool set_can_equip )
{ can_equip = set_can_equip; }
bool get_can_equip()
{ return can_equip; }
void set_can_attack( bool set_can_attack )
{ can_attack = set_can_attack; }
bool get_can_attack( ) { return can_attack; }
void set_can_defend( bool set_can_defend )
{ can_defend = set_can_defend; }
bool get_can_defend( ) { return can_defend; }
void set_can_drink( bool set_can_drink )
{ can_drink = set_can_drink; }
bool get_can_drink() { return can_drink; }
void set_can_eat( bool set_can_eat )
{ can_eat = set_can_eat; }
bool get_can_eat() { return can_eat; }
void set_can_use( bool set_can_use )
{ can_use = set_can_use; }
bool get_can_use() { return can_use; }
void set_is_consumab le( bool set_is_consumab le )
{ is_consumable = set_is_consumab le; }
bool get_is_consumab le() { return is_consumable; }
void set_is_magical( bool set_is_magical )
{ is_magical = set_is_magical; }
bool get_is_magical( ) { return is_magical; }
void describe(); // simply returns description (see below)
void clear_describe( ); // clears description
void add_describe( string line_to_add );
/*Line above checks to see if description is set to either
need_set or desc_cleared, and if so description.cle ar()
then push_back( line_to_add ), else just
push_back( line_to_add)*/
private:
// These are stats that will be set for every item created
string need_set; // description is initialized with this
string desc_cleared; // description will be set to this
//after it has been cleared
vector<stringde scription;
// This is to allow multi-line descriptions
float item_weight; // These are pretty self explanatory I think
bool can_equip;
bool can_attack;
bool can_defend;
bool can_drink;
bool can_eat;
bool can_use;
bool is_consumable;
bool is_magical;
};
#endif
but as I read along I was confused over something. The above works just
fine, but I was also wondering should the constructor be this:
Item( float weight = 0,\
bool set_can_equip = false,\
bool set_can_attack = false,\
bool set_can_defend = false,\
bool set_can_drink = false,\
bool set_can_eat = false,\
bool set_can_use = false,\
bool set_is_consumab le = false,\
bool set_is_magical = false );
with a constructor body like this in the cpp file:
Item::Item( float weight,\
bool set_can_equip,\
bool set_can_attack, \
bool set_can_defend, \
bool set_can_drink,\
bool set_can_eat,\
bool set_can_use )
{
item_weight = weight;
can_equip = set_can_equip;
can_attack = set_can_attack;
can_defend = set_can_defend;
can_drink = set_can_drink;
can_eat = set_can_eat;
can_use = set_can_use;
is_consumable = set_is_consumab le;
is_magical = set_is_magical;
need_set = "You need to set a description here!\n";
desc_cleared = "The description has been cleared.\n";
description.cle ar();
description.pus h_back( need_set );
}
or this:
Item() : float weight( 0 ),\
bool can_equip( false ),\
bool can_attack( false ),\
bool can_defend( false ),\
bool can_drink( false ),\
bool can_eat( false ),\
bool can_use( false ),\
bool is_consumable( false ),\
bool is_magical( false );
and lose the entire body of the constructor in the cpp file? I will need
to pass in parameters to override the defaults when I instantiate the
objects.
Question 1: Is this a mal-formed class header?
Question 2: Which should I use for the initialization list?
Thanks in advance.
DN
--
[there are no x's in my email]
I have the right to remain silent
(and should probably use it as much as possible)
Anything I type can and will be used against me
in a court of idiocy
I have the right to be wrong
(and probably am)
If I can not furnish my own wrongness
I'm sure someone will provide it for me.