| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Using 'class's after their created
I am making a chess game that has three classes involved in it, a board class, a pieces class, and a movement class. Well the problem I am having is not making the classes themselves but with initializing them to be used later. I am basically having a problem understanding the concept of using them later and well, I have read two books that describe classes in them, but they only describe how to create one. So I have compiled the classes and they compile fine but when I try to initialize them in the main void I always get an error like first time declared or invalid conversion of const char to char.
So to make a long story short does anyone have a good site that I can read about classes and how to use them later, I understand the fact that you should think of it like building a car, piece by piece, and well I can build all the pieces but when it comes to final assembly I don't know were to put the freakin doors, and the windows don't fit. lol. |
|
#2
|
|||
|
|||
|
Quote:
cause if thats the problem then here is a book i got which i give 5 stars out of 5 its called Beginnin C++ Game Programming by: Micheal Dawson and here is a good soucre good to understand classes Code:
#include <iostream>
using namespace std;
class Critter
{
public:
int m_Hunger;
Critter(int hunger = 0); //constructor prototype
void Greet();
};
Critter::Critter(int hunger) //construcyot definition
{
cout<< "A new critter has been born!"<< endl;
m_Hunger = hunger;
}
void Critter::Greet()
{
cout<< "Hi. I'm critter. My hunger level is "<< m_Hunger <<
".\n\n";
}
int main()
{
Critter crit(7)
crit.Greet();
return 0;
}
but if u got a compiler like mine that doesnt let u do it here is the code Code:
#include <iostream>
using namespace std;
class Critter
{
public:
int m_Hunger;
Critter(int hunger = 0); //constructor prototype
void Greet();
};
Critter::Critter(int hunger) //construcyot definition
{
cout<< "A new critter has been born!"<< endl;
m_Hunger = hunger;
}
void Critter::Greet()
{
cout<< "Hi. I'm critter. My hunger level is "<< m_Hunger << ".\n\n";
}
int main()
{
Critter crit(7);
crit.Greet();
cin.get();
}
now cause u didnt say what was the name of ur class and also cause u didnt show any code i cant show what u did wrong but that's how i can help u oh yeah also if u dont understand just say so so i can explain part by part cause i know how it works k i hoped i helped |
|
#3
|
||||
|
||||
|
I will have to go look that book up because the two I got are only for beginners and sometimes in order to understand something you not only need to know how to do something but why and were you would need to use it. My code is not complete that's why I didn't post it, mostly because chess is a very complicated game in the first place and trying to make a console game that acts like you are playing chess is even more complicated. I am constantly re-writing my code in order to try new things and see if they work properly. So the further I get along, I will show you some results. now this is one of those cases were ppl don't usually mind you posting source code =). Thx for helping by the way.
|
|
#4
|
|||
|
|||
|
yo just read what u put and u said u doin chess and i was wondering r u using opengl or just C++ cause i got a book called
Beginnin OpenGL GameProgramming (wierd but 2 names in front) Dave Astle, Kevin Hawkins and even though i have not read i looked at it and it seems it will teach u how to do chess in opengl |
|
#5
|
||||
|
||||
|
Im only using C++ right now I dont even really know what openGl is yet, or what its used for. I wanted to get good at one thing first. I got school classes to, so trying to learn school crap and C++ is really straining my brain right now,lol. But maybe you got a link that could explain what openGL is first.
|
|
#6
|
|||
|
|||
|
nah ill tell u myself instead it stans for open grahics libary it is when u want to make good games when u there is color or just simple graphic in the program with it u can add visual chess pieces not words or numbers u in school or a programmin class? cause i checked if i could get it and i need to get typing class first then freakin java!! no C++ in the whole high school so that is y i read books about it
|
|
#7
|
||||
|
||||
|
Well, I'm in college right now and Ive only been programming for about three months, and I haven't made it too my main classes yet, but just trying to get a head start. Now is openGL some kind of separate language or is it a type of library or something used in C++, Ill probably just look it up but it might be beyond my scope just yet.
Well I would do what I had to do if it was something I wanted to get started in, plus typing comes in handy and going by a lot of your posts you could probably use it. J/K Plus you can take what they give you and still learn C++ on the side by the time you graduate you will be ahead of the game. I wish when I was in high school they offered any type of computer classes other then auto CAD and typing. Well preciate the help and I think I'm making ground on this now just had to get over that little mental block I was having. Really just needed to take a break for a bit. |
|
#8
|
|||
|
|||
|
i cant say its only for C++ but i can tell u that u do need another program which comes with the
yo do u want to become a game programmer or what do u want to do with C++? |
|
#9
|
||||
|
||||
|
I want to program everything, I want to be able to be well rounded not just focused on one particular area so's to speak. Just want to learn the language and be fluent at it. That way I can program what I want and I'm not confined to just knowing all about programming games but mediocre at everything else. =)
I can use my compiler to write openGL but just dont know what it does yet so its kinda not useful right now. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Using 'class's after their created |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|