[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. 15 1214
Devon Null wrote:
[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;
Never, ever put this line in a header.
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 );
Why are all those continuation characters there?
--
Ian Collins.
"Devon Null" <th************ *@xgmailx.comwr ote in message
news:u6******** *************** *******@comcast .com...
[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?
I would probably do it similar to this (notice also renaming of variables
and methods):
#ifndef ITEMS_HEADER_
#define ITEMS_HEADER_
#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 weight( float Weight )
{ weight_ = Weight; }
float weight()
{ return weight_; }
void equipable( bool Can_equip )
{ equipable_ = Can_equip; }
bool equipable()
{ return equipable_; }
void attackable( bool Can_attack )
{ attackable_ = Can_attack; }
bool attackable()
{ return attackable_; }
void defendable( bool Can_defend )
{ defendable_ = Can_defend; }
bool defendable()
{ return defendable_; }
void drinkable( bool Can_drink )
{ drinkable_ = Can_drink; }
bool drinkable()
{ return drinkable_; }
void eatable( bool Can_eat )
{ eatable_ = Can_eat; }
bool eatable() { return eatable_; }
void useable( bool Can_use )
{ useable_ = Can_use; }
bool useable()
{ return useable_; }
void consumable( bool Is_consumable )
{ consumable_ = Is_consumable; }
bool consumable()
{ return consumable_; }
void magical( bool Is_magical )
{ magical_ = Is_magical; }
bool magical()
{ return 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 weight_; // These are pretty self explanatory I think
bool equipable_;
bool attackable_;
bool defendable_;
bool drinkable_;
bool eatable_;
bool useable_;
bool consumable_;
bool magical_;
};
#endif
Item::Item( float weight,
bool equipable,
bool attackable,
bool defendable,
bool drinkable,
bool eatable,
bool useable,
bool consumable,
bool magical ): weight_( weight ), equipable_( equipable ),
attackable_( attackable ), defendable_( defendable ),
drinkable_( drinkable ), eatable_( eatable ),
useable_( useable ), consumable_( consumable ),
magical_( 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 );
}
Jim Langston wrote:
>
I would probably do it similar to this (notice also renaming of variables
and methods):
#ifndef ITEMS_HEADER_
#define ITEMS_HEADER_
#include <iostream>
#include <string>
#include <vector>
using namespace std;
Are you sure you'd do this?
--
Ian Collins.
"Ian Collins" <ia******@hotma il.comwrote in message
news:5c******** *****@mid.indiv idual.net...
Jim Langston wrote:
>> I would probably do it similar to this (notice also renaming of variables and methods):
#ifndef ITEMS_HEADER_ #define ITEMS_HEADER_
#include <iostream> #include <string> #include <vector>
using namespace std;
Are you sure you'd do this?
Er, no, nice catch. I copied the code and modified it, didn't even notice
that line. I *never* use using namespace xxxx;
Jim Langston wrote:
bool equipable_;
bool attackable_;
bool defendable_;
bool drinkable_;
bool eatable_;
bool useable_;
bool consumable_;
bool magical_;
Out of curiosity, why append underscores too all the variable names?
--
[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.
Ian Collins wrote:
>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 );
Why are all those continuation characters there?
They are simply there in the post - that is one continuous line in the
actual code, no continuation marks in the code. It look REALLY messy
with word wrap, so I tried to break the lines to control the breaks.
--
[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.
Ian Collins wrote:
>
>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 );
Why are all those continuation characters there?
Maybe the guy who wrote it was a BASH convert :).
cheers,
- J.
Devon Null wrote:
Jim Langston wrote:
bool equipable_;
bool attackable_;
bool defendable_;
bool drinkable_;
bool eatable_;
bool useable_;
bool consumable_;
bool magical_;
Out of curiosity, why append underscores too all the variable names?
That's a fairly common use to differentiate member variables from
others.
Brian
"Devon Null" <th************ *@xgmailx.comwr ote in message
news:d4******** *************** *******@comcast .com...
Jim Langston wrote:
> bool equipable_; bool attackable_; bool defendable_; bool drinkable_; bool eatable_; bool useable_; bool consumable_; bool magical_;
Out of curiosity, why append underscores too all the variable names?
I tried to come up with some way to differentiate varaibles that are a
method of my class and private with varaibles/methods that arn't. I find it
is makes it easy if I need setters and getters. Consider drinkable, whoudl
I would actually call Drinkable_.
The setter would be
void Drinkable( bool drinkable ) { Drinkable_ = drinkable; }
The getter would be:
bool Drinkable() const { return Drinkable_; }
This makes it easy to use this class.
class Foo;
Foo.Drinkable( true );
if ( Foo.Drinkalbe() )
// ...
The users of hte class shouldn't worry about what my variable is called.
Drinkable is already a boolean concept (yes or no) so why should I have to
say IsDrinkable? And if I want to set it, why have to say SetDrinkable?
Doesn't Drinkable( true ) express that? I saw the trailing underscores used
and found it the best to my liking, so I use it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Craig S. Ugoretz |
last post by:
Dear newgroup readers,
I am pleased to announce the presentation of the new open source
software project I have created, called the "Wisdom Seeker IDE". For
a description of what open source software is about, see the web site
http://www.opensource.org/. The web site for my(our) project is
http://ws-ide.sourceforge.net/ws-ide.htm. It has a
philosophical/political theme to it, based upon a work by the Greek
philosopher Plato called...
|
by: Melody Droid |
last post by:
I recently made some conceptual breakthroughs regarding the interval
permutation pre-sorting and the pitch-class-set/scale post-sorting
aspects of my envisioned symmetrical melody thesaurus software, so
that it will take the absolute minimum of time and effort to write a
computer program for it and bring it up to the demo level in order to
shop the project around.
I've created a Yahoo Group for the project over here:
...
|
by: Steven O. |
last post by:
I am seeking some kind of tool that I can use for GUI prototyping. I
know how to use Visual Basic, but since a lot of software is being
coded in Java or C++, I'd like to learn a Java or C++ -based tool.
Back when I took my Java and C++ classes (two or three years ago), the
available tools -- at least the ones I could find -- were still not as
easy, not as "drag-and-drop", as Visual Basic. Has that changed?
Is there some software out...
|
by: Maboroshi |
last post by:
Hi I am fairly new to programming but not as such that I am a total beginner
From what I understand C and C++ are faster languages than Python. Is this
because of Pythons ability to operate on almost any operating system? Or is
there many other reasons why?
I understand there is ansi/iso C and C++ and that ANSI/ISO Code will work on
any system
If this is the reason why, than why don't developers create specific Python
Distrubutions...
|
by: David |
last post by:
I am a full-time freelance writer. I am seeking an established,
professional web designer who has designed more than one successful
website for freelance writers.
The individual needs to be able to do the whole job including content,
design, graphics and logo. I may want some input or to supply text to
work with for the content for obvious reasons. They need to be able to
demonstrate that the sites they have done for writers have been...
| |
by: Sugapablo |
last post by:
Just out of curiosity, while checking on a site I was working on, I
decided to throw a couple of the web's most popular URLs into the W3C
Markup Validator.
Out of microsoft.com, google.com, amazon.com, yahoo.com, aol.com, and
mozilla.org, only Mozilla's site came back "Valid HTML".
So if all these places, with their teams of web developers don't seem to
care, should the rest of us small time web devs concern ourselves with
standards?...
|
by: Jim |
last post by:
Hi,
I am hoping that someone here can help me out. I am for the first time
trying to implement a page design using only CSS instead of HTML
tables.
I've been able to get most of the page done ok. I have my header area
and below it 3 columns.
My problem is within the header area.
|
by: Devon Null |
last post by:
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;
|
by: dhcrusoe |
last post by:
Greetings,
My apologies if this message comes across as spam; it isn't meant to
be.
A group of colleagues and I have built a project to mobilize
technology volunteers for small nonprofit organizations, located at
http://www.codekindness.org . It's a simple technology, and simply
acts to link potential volunteers with individual projects. It's
nonprofit.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |