.h HELP dont get it

Posts 1–15 of 26 · Page 1 of 2
.h HELP dont get it
im tring use heather file (.h ) and all that stuff but i get an error i dont get how if some one know how to help me PLZ so here whats going on:

p.s this is smal example im trying to figure it out im using code::block btw


in my main.cpp fille i got
/////////////////////////////////////////////////////////////////////////////////////////
Code:
#include <iostream>
#include "Archer.h"

using namespace std;

int main()
{

    Archer ONE;



    return 0;
}

///////////Archer.h////////////////in the heather(.h) i got/////////////////
Code:
#ifndef ARCHER_H_INCLUDED
#define ARCHER_H_INCLUDED






class Archer
{
 public:

 void StartingStats()
 {
    Health = 100;
 }

 private:
 int Health;

}
#endif // ARCHER_H_INCLUDED
/////////////////////////////////////////// ////////////////////////////////////////


you guys can help me out plz i know this is stupid but i dont get it i folowed guide and all no? the error im geting is

C:\Users\Sawm\Desktop\code block\guess my number\Fucking fail\main.cpp|4|error: expected unqualified-id before "using"|
||=== Build finished: 1 errors, 0 warnings ==



im geting mad i cant quit this is my dream stil i suck at it
there's a comma where there shouldn't be one
Archer ONE,;
vs
Archer ONE;

Also your #endif line should be at the end of the HEADER file
corected but im geting SAME error sry made this realy fast as a example of me not being able tu use header files xD
put the #endif line OUTSIDE of the last } symbol
it needs to be the very last line in header file

also it looks like you're not only defining but implementing a class in the header file?
Quote Originally Posted by B1ackAnge1 View Post
put the #endif line OUTSIDE of the last } symbol
it needs to be the very last line in header file

also it looks like you're not only defining but implementing a class in the header file?
what? sorry im totaly new to c++ and i dont get it noob friendly? plz
Hmmm looks as if you jumped into classes a little too quickly. I will quickly go over the basic problems in each file, but you really need to learn how classes work or you will run into more errors.

Archer.h
Ok, firstly I'm not sure why you have all the define statements in the beginning all I can tell you is that they are not neccessary, so I will remove all of them.
Code:
class Archer
{
 public:

 void StartingStats()
 {
    Health = 100;
 }

 private:
 int Health;

}
So now we have this. Now when defining a class everything is private by defualt. There is no need to declare any variables priavate unless that's just your style. In any case I will change that:

Code:
class Archer
{ 
 int Health;
 public:

 void StartingStats()
 {
    Health = 100;
 }

}
See how I moved your int declaration before public: this make your int Health private by default.
At the end of your class you will need to add a semicolon:
Code:
class Archer
{ 
 int Health;
 public:

 void StartingStats()
 {
    Health = 100;
 }

};
Okay now this header file is done. on to your main method:

Code:
#include <iostream>
#include "Archer.h"

using namespace std;

int main()
{

    Archer ONE,;



    return 0;
}
Looks simple enough. Just remove that "," comma it doesn't need to be there. And you could make it do something while you were at it, such as call one of your objects methods.
Code:
#include <iostream>
#include "Archer.h"

using namespace std;

int main()
{
    Archer ONE;
    One.StartingStats();

    return 0;
}
Oh and I see BA has explained the #endif statements. Do what he says as far as that. And if you don't know how the header system works just define the class inside the same file. It's not going to blow up or something..
the #ifdef's are to make sure the header file only gets included once.

the above plus the missing ';' after defining a class as Why 06 pointed out i'm 99% sure was your issue
THANKS TO ALL I LOVE YOU one last question if u want just because you explain so well if i wana put lets say stuf like

void Stats()
{
cout<<"Your Hp is: "<<Health;
}

in that class and put it in a seperate .cpp file so i dont have to put it in the main.cpp file how would i do that? :S i saw something about
Archer::Stats()
{
cout<<"Your Hp is: "<<Health;
}

i said SOMETHING LIKE THAT not thats how its done... if its to long ore complex just tell me ime just go read a book xD
It's not hard or complex at all it's just another function. Place it in the same place you place the last one.
well thanks guys ima read more obviously i suck at this -_- thanks alot if neone got power to close this they can im all done thanks alot alot alot (why06 == god) :O
Quote Originally Posted by sawm444 View Post
well thanks guys ima read more obviously i suck at this -_- thanks alot if neone got power to close this they can im all done thanks alot alot alot (why06 == god) :O
Well if you believe that, then you really have a lot more to learn, I am but a humble nub In a see of experienced coders. Now BA is a pro. I even messed up on that little header file thing, luckily he corrected my mistake .
ya didn't mess up - you just hadn't seen it before
thanks for not making fun of the way i type... all the other forums tell me to gtfo and learn how to spell...wtf i have feelings...
ehhh i got another question and i didn't wanna make another topic for it since the c++ forum activity isint usually very active and i don't wanna spam this place with 100 different help topics eh so here it goes:

i first used devc++ but then my friend was like " ehh well its old and doesn't get updated much" and said "you'd like code::block better man" and well he knows me pretty well because i do like code::block better but now i see that every ones using visual studio and i was wondering WHY? is it really that better? i was confused using it i would always get a load of errors that i didn't get in code::block using visual c++ and ehh is that bad? like wen i learn more stuff will i have to move on to visual c++ because its better? what i mean is should i learn how to use it ore its just a question of what u rather use? its confused me a lot to wonder if the way im coding would not work in another compiler and all that please clear my mind on the difference? :S

sorry if this is incomprehensible i suck at English
Quote Originally Posted by sawm444 View Post
ehhh i got another question and i didn't wanna make another topic for it since the c++ forum activity isint usually very active and i don't wanna spam this place with 100 different help topics eh so here it goes:

i first used devc++ but then my friend was like " ehh well its old and doesn't get updated much" and said "you'd like code::block better man" and well he knows me pretty well because i do like code::block better but now i see that every ones using visual studio and i was wondering WHY? is it really that better? i was confused using it i would always get a load of errors that i didn't get in code::block using visual c++ and ehh is that bad? like wen i learn more stuff will i have to move on to visual c++ because its better? what i mean is should i learn how to use it ore its just a question of what u rather use? its confused me a lot to wonder if the way im coding would not work in another compiler and all that please clear my mind on the difference? :S

sorry if this is incomprehensible i suck at English
I use visual studio because it makes windows programming easier. As an ide i think i like eclipse more because of it's more advanced remembering of classes-ness, But visual studio is just easy to use, thus i have to think less.
Posts 1–15 of 26 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us