User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion

Reply
Thread Tools Display Modes
Unread 22 Oct 2002, 03:51   #1
hartmch
Guest
 
Posts: n/a
cpp problem

Im having trouble debuging a program im working on. I have 3 errors and i cant figure out why. Any help would be appreciated

Quote:
monster.h



/***********************************************

character.h -- Interface file for type "character"

***********************************************/

#ifndef MONSTER_
#define MONSTER_

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

class monster
{
public:

monster ( vector<string> initName("1","Old Man"),
int initLife = 100,
int initDext = 5,
int initFirstDamage = 15,
int initSecondDamage = 20,
int initThirdDamage = 25,
int initFirstBigDamage = 65,
int initSecondBigDamage = 70,
int initThirdBigDamage = 75,
vector<string> initFirstAttackText(1,"the first attack text"),
vector<string> initFirstBigText(1, "the first big atack text"),
vector<string> initSecondAttackText(1,"the second attack text"),
vector<string> initSecondBigText(1, "the second big attack text"),
vector<string> initThirdAttackText(1, "the third attack text"),
vector<string> initThirdBigText(1, "the third big attack text"),
int initAbilityOne = 1,
int initAbilityTwo = 2,
int initEffectOne = 3,
int initChangeOne = 4,
int initCorresAttackOne = 1,
vector<string> initEffectOneText(1, "effect one's text"),
int initEffectTwo = 21,
int initChangeTwo = 22,
int initCorresAttackTwo = 2,
vector<string> initEffectTwoText(1. "effect two's text"),
int initSmallHurt = 5,
int initBigHurt = 15,
vector<string> initSmallText(1, "he was hurt a little"),
vector<string> initBigText(1, "you did some good damage"),
vector<string> initNearDeath(1, "he is near death"),
vector<string> initDeath(1, "he is as dead as dead can be") );


monster (const monster & Existing );

monster& operator= (const monster& Rightside);

vector<string> getName() const;

int getDext() const;

int getFirstDamage() const;

int getSecondDamage() const;

int getThirdDamage() const;

int getFirstBigDamage() const;

int getSecondBigDamage() const;

int getThirdBigDamage() const;

vector<string> getFirstAttackText() const;

vector<string> getFirstBigText() const;

vector<string> getSecondAttackText() const;

vector<string> getSecondBigText() const;

vector<string> getThirdAttackText() const;

vector<string> getThirdBigText() const;

int getAbilityOne() const;

int getAbilityTwo() const;

int getEffectOne() const;

int getChangeOne() const;

int getCorresAttackOne() const;

vector<string> getEffectOneText() const;

int getEffectTwo() const;

int getChangeTwo() const;

int getCorresAttackTwo() const;

vector<string> getEffectTwoText() const;

int getSmallHurt() const;

int getBigHurt() const;

vector<string> getSmallText() const;

vector<string> getBigText() const;

vector<string> getNearDeath() const;

vector<string> getDeath() const;

void setName( vector<string> );

void setDext( int );

void setLife( int );

void setFirstDamage( int );

void setSecondDamage( int );

void setThirdDamage( int );

void setFirstBigDamage( int );

void setSecondBigDamage( int );

void setThirdBigDamage( int );

void setSmallHurt( int );

void setBigHurt( int );

void write (ostream& ) const;

void read (istream&);

bool operator==( const monster& RHS ) const;

bool operator!=( const monster& RHS ) const;

friend ostream& operator<<( ostream& Out, const monster& Item );

friend istream& operator>>( istream& In, monster& Item );



private:

vector<string> name;

int life;

int dext;

int first_damage;

int second_damage;

int third_damage;

int first_big_damage;

int second_big_damage;

int third_big_damage;

vector<string> first_attack_text;

vector<string> first_big_text;

vector<string> second_attack_text;

vector<string> second_big_text;

vector<string> third_attack_text;

vector<string> third_big_text;

int ability_one;

int ability_two;

int effect_one;

int change_one;

int corres_attack_one;

vector<string> effect_one_text;

int effect_two;

int change_two;

int corres_attack_two;

vector<string> effect_two_text;

int small_hurt;

int big_hurt;

vector<string> small_text;

vector<string> big_text;

vector<string> near_death;

vector<string> death;

void validate();

};

#endif
Quote:
monster.cpp



#include <iostream>
#include <iomanip>
#include <vector>
#include <fstream>


using namespace std;

#include "monster.h"

monster::monster( vector<string> initName,
int initLife,
int initDext,
int initFirstDamage,
int initSecondDamage,
int initThirdDamage,
int initFirstBigDamage,
int initSecondBigDamage,
int initThirdBigDamage,
vector<string> initFirstAttackText,
vector<string> initFirstBigText,
vector<string> initSecondAttackText,
vector<string> initSecondBigText,
vector<string> initThirdAttackText,
vector<string> initThirdBigText,
int initAbilityOne,
int initAbilityTwo,
int initEffectOne,
int initChangeOne,
int initCorresAttackOne,
vector<string> initEffectOneText,
int initEffectTwo,
int initChangeTwo,
int initCorresAttackTwo,
vector<string> initEffectTwoText,
int initSmallHurt,
int initBigHurt,
vector<string> initSmallText,
vector<string> initBigText,
vector<string> initNearDeath,
vector<string> initDeath)
{
name = initName;

life = initLife;
dext = initDext;
first_damage = initFirstDamage;
second_damage = initSecondDamage;
third_damage = initThirdDamage;
first_big_damage = initFirstBigDamage;
second_big_damage = initSecondBigDamage;
third_big_damage = initThirdBigDamage;

first_attack_text = initFirstAttackText;

first_big_text = initFirstBigText;

second_attack_text = initSecondAttackText;

second_big_text = initSecondBigText;

third_attack_text = initThirdAttackText;

third_big_text = initThirdBigText;

ability_one = initAbilityOne;
ability_two = initAbilityTwo;
effect_one = initEffectOne;
change_one = initChangeOne;
corres_attack_one = initCorresAttackOne;

effect_one_text = initEffectOneText;

effect_two = initEffectTwo;
change_two = initChangeTwo;
corres_attack_two = initCorresAttackTwo;

effect_two_text = initEffectTwoText;

small_hurt = initSmallHurt;
big_hurt = initBigHurt;

small_text = initSmallText;

big_text = initBigText;

near_death = initNearDeath;

death = initDeath;

validate();

}

monster::monster (const monster & Existing )
{

name = Existing.name;

life = Existing.life;
dext = Existing.dext;
first_damage = Existing.first_damage;
second_damage = Existing.second_damage;
third_damage = Existing.third_damage;
first_big_damage = Existing.first_big_damage;
second_big_damage = Existing.second_big_damage;
third_big_damage = Existing.third_big_damage;

first_attack_text = Existing.first_attack_text;

first_big_text = Existing.first_big_text;

second_attack_text = Existing.second_attack_text;

second_big_text = Existing.second_big_text;

third_attack_text = Existing.third_attack_text;

third_big_text = Existing.third_big_text;

ability_one = Existing.ability_one;
ability_two = Existing.ability_two;
effect_one = Existing.effect_one;
change_one = Existing.change_one;
corres_attack_one = Existing.corres_attack_one;

effect_one_text = Existing.effect_one_text;

effect_two = Existing.effect_two;
change_two = Existing.change_two;
corres_attack_two = Existing.corres_attack_two;

effect_two_text = Existing.effect_two_text;

small_hurt = Existing.small_hurt;
big_hurt = Existing.big_hurt;

small_text = Existing.small_text;

big_text = Existing.big_text;

near_death = Existing.near_death;

death = Existing.death;
}

monster& monster::operator=( const monster& Rightside )
{
name = Rightside.name;

life = Rightside.life;
dext = Rightside.dext;
first_damage = Rightside.first_damage;
second_damage = Rightside.second_damage;
third_damage = Rightside.third_damage;
first_big_damage = Rightside.first_big_damage;
second_big_damage = Rightside.second_big_damage;
third_big_damage = Rightside.third_big_damage;

first_attack_text = Rightside.first_attack_text;

first_big_text = Rightside.first_big_text;

second_attack_text = Rightside.second_attack_text;

second_big_text = Rightside.second_big_text;

third_attack_text = Rightside.third_attack_text;

third_big_text = Rightside.third_big_text;

ability_one = Rightside.ability_one;
ability_two = Rightside.ability_two;
effect_one = Rightside.effect_one;
change_one = Rightside.change_one;
corres_attack_one = Rightside.corres_attack_one;

effect_one_text = Rightside.effect_one_text;

effect_two = Rightside.effect_two;
change_two = Rightside.change_two;
corres_attack_two = Rightside.corres_attack_two;

effect_two_text = Rightside.effect_two_text;

small_hurt = Rightside.small_hurt;
big_hurt = Rightside.big_hurt;

small_text = Rightside.small_text;

big_text = Rightside.big_text;

near_death = Rightside.near_death;

death = Rightside.death;

return *this;
}

vector<string> monster::getName() const
{
return name;
}

int monster::getDext() const
{
return dext;
}

int monster::getFirstDamage() const
{
return first_damage;
}

int monster::getSecondDamage() const
{
return second_damage;
}

int monster::getThirdDamage() const
{
return third_damage;
}

int monster::getFirstBigDamage() const
{
return first_big_damage;
}

int monster::getSecondBigDamage() const
{
return second_big_damage;
}

int monster::getThirdBigDamage() const
{
return third_big_damage;
}

vector<string> monster::getFirstAttackText() const
{
return first_attack_text;
}

vector<string> monster::getFirstBigText() const
{
return first_big_text;
}

vector<string> monster::getSecondAttackText() const
{
return second_attack_text;
}

vector<string> monster::getSecondBigText() const
{
return second_big_text;
}

vector<string> monster::getThirdAttackText() const
{
return third_attack_text;
}

vector<string> monster::getThirdBigText() const
{
return third_big_text;
}

int monster::getAbilityOne() const
{
return ability_one;
}

int monster::getAbilityTwo() const
{
return ability_two;
}

int monster::getEffectOne() const
{
return effect_one;
}

int monster::getChangeOne() const
{
return change_one;
}

int monster::getCorresAttackOne() const
{
return corres_attack_one;
}

vector<string> monster::getEffectOneText() const
{
return effect_one_text;
}

int monster::getEffectTwo() const
{
return effect_two;
}

int monster::getChangeTwo() const
{
return change_two;
}

int monster::getCorresAttackTwo() const
{
return corres_attack_two;
}

vector<string> monster::getEffectTwoText() const
{
return effect_two_text;
}

int monster::getSmallHurt() const
{
return small_hurt;
}

int monster::getBigHurt() const
{
return big_hurt;
}

vector<string> monster::getSmallText() const
{
return small_text;
}

vector<string> monster::getBigText() const
{
return big_text;
}

vector<string> monster::getNearDeath() const
{
return near_death;
}

vector<string> monster::getDeath() const
{
return death;
}

void monster::setName( vector<string> given)
{
name = given;
}

void monster::setDext( int given)
{
dext = given;
}

void monster::setLife( int given)
{
life = given;
}

void monster::setFirstDamage( int given)
{
first_damage = given;
}

void monster::setSecondDamage( int given)
{
second_damage = given;
}

void monster::setThirdDamage( int given)
{
third_damage = given;
}

void monster::setFirstBigDamage( int given)
{
first_big_damage = given;
}

void monster::setSecondBigDamage( int given)
{
second_big_damage = given;
}

void monster::setThirdBigDamage( int given)
{
third_big_damage = given;
}

void monster::setSmallHurt( int given)
{
small_hurt = given;
}

void monster::setBigHurt( int given)
{
big_hurt = given;
}

void monster::write (ostream& Out) const
{
Out << "\n\nYo, your thingy wrote Out\n";
}

void monster::read (istream& In)
{
In >> life;
}

bool monster::operator==( const monster& RHS ) const
{
return (name[0] == RHS.name[0] );
}

bool monster::operator!=( const monster& RHS ) const
{
return (name[0] != RHS.name[0] );
}

ostream& operator<<( ostream& Out, const monster& Item )
{
Item.write(Out);
}

istream& operator>>( istream& In, monster& Item )
{
Item.read(In);
}

void monster::validate()
{
cout << "\nValidated\n";
}
  Reply With Quote
Unread 22 Oct 2002, 07:26   #2
mogrika
Guest
 
Posts: n/a
the errors are?
  Reply With Quote
Unread 22 Oct 2002, 08:11   #3
mbushell
Registered User
 
mbushell's Avatar
 
Join Date: Jul 2000
Location: :noitacoL
Posts: 1,200
mbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus would
Quote:
Originally posted by mogrika
the errors are?
I think he gives you the source so you can see for youself ;-)
mbushell is offline   Reply With Quote
Unread 22 Oct 2002, 17:08   #4
hartmch
Guest
 
Posts: n/a
g:\monster.h(22) : error C2629: unexpected 'class monster ('
g:\monster.h(22) : error C2238: unexpected token(s) preceding ';'
G:\monster.cpp(42) : error C2511: 'monster::monster' : overloaded member function 'void (class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<cha
  Reply With Quote
Unread 22 Oct 2002, 18:35   #5
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
type a #ENDIF below the #DEFINE MONSTER_ or at some other place where you want to stop the IFNDEF. That to start with.
I don't know if that's the problem but if it's not, it'd be wise to comment out some of the functions, to start with the constructor.
Try to isolate the problem like that, comment out the problem lines.

Something else would be the name of your class... classnames always start with a CAPITAL. Atleast that's what I learnt. Don't believe it's compulsory for the compiler tho

Other things, like health, damages, dext, are USUALLY constant (as you've defined with the default parameter). Try to make those member variables instead of parameters given in the constructor.

Some other tip would be to make a few more functions, like
Monster::setText(char* text, int type), that would set the text you now give in the constructor. With the type parameter you could either set the AttackText, or other texts. Make a huge switch of it.

When you write code it's quite handy to make it readable too. In a case like this, when debugging, it's easier to filter out a problem spot.
__________________
"Yay"
Structural Integrity is offline   Reply With Quote
Unread 22 Oct 2002, 19:17   #6
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Re: cpp problem

monster.h Line 22
monster ( vector<string> initName("1","Old Man"),
Well the 1 shouldn't be quoted. Also this isn't how to do default values for arguments, try:
monster ( vector<string> initName = vector<string>(1,"Old Man"),
you do this a few times

Line 46:
vector<string> initEffectTwoText(1. "effect two's text"),
A period used instead of a comma.

If you have problems solving the other errors just ask again
queball is offline   Reply With Quote
Unread 23 Oct 2002, 04:31   #7
hartmch
Guest
 
Posts: n/a
Thanks for your help queball and Structural Integrity. Ive made those changes and I still have the same 3 errors. thanks for your help though, im sure ill figure it out soo enough
  Reply With Quote
Reply


Thread Tools
Display Modes

Forum Jump


All times are GMT +1. The time now is 03:48.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018