Archived

This topic is now archived and is closed to further replies.

Newbie C++! Please Help!

This topic is 5648 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya all I have been programming Pascal and C before but not c++! I do know how function work. But I dont know how class, private or public work....can anyone help me out please? Cheer all HOTSHOT P.S. it would be nice if someone teach me from Pascal to c++ cos I will be able to understand as I''m master of Pascal but not c++....I hope u understand what I''m saying!

Share this post


Link to post
Share on other sites
The following link is to a free C++ book that''ll teach you about C++ programming, and of course OOP.

http://www.xtremejava.com/books/index.html

Else, get C++ Primer by Lipmann from Amazon or another book-pusher.

ENJOY

**************************
A year spent in artificial intelligence is enough to make one believe in God.

Share this post


Link to post
Share on other sites
To get the basics down you could start here, which is a list of beginner tutorials and free online books for C++ programming (the links at the top will take you to more advanced concepts). If you're willing to spend some money you can buy C++ For Pascal Programmers. Finally if you don't have a c++ compiler I would suggest trying Bloodshed, which is a free C++ compiler for windows.

These resources should get you started in C++ programming, when you get stuck on something or find a tutorial doesn't explain a particular concept very well drop in and post a message. There are lots of people on this site willing to help out, I'm here most of the day (Eastern Time, US & Canada) either answering questions or engaging in conversations in the lounge, and other members like Saberman seem to spend most of their Gamedev time helping people in this forum and others.


[edited by - Michalson on June 25, 2002 5:14:11 PM]

Share this post


Link to post
Share on other sites
It seems like you have the same knowledge as I had for a short time ago. I was programming C for some time but did actually never learn anything advanced, I did almost loose all my motivation (I couldnt get anything working; how depresing!), until I bougth the book "teach yourself C++ in 21 days". As I read did I find out that I knew less than what the book teached the first five days! I'm about finishing the second week now and is beginning to read "windows gameprogramming for dummis" (contents directX and Windows-programming) parallelly (I didnt spell that right huh? ), something I never thought I was able to do! Try theese (or some other) books, succes is the only thing that keeps us motivated!
__________________________________
Just forget about it! I won't write any kind of a profile signature!

[edited by - the Chef on June 25, 2002 5:51:58 PM]

Share this post


Link to post
Share on other sites
Hiya all,

Thank to all for helping me. Hey Michalson, which bloodshed...should I download?

This is my first program!

// Age program
# include
# include
# include
//my first c++

Class Person
{
Private
int age;
Public
void setage();
void showage();
}

void person :: setage();
{
int n;

puts("your age");
scanf("%d%c",&n)
age=n;
}

void person :: showage();
{

printf("Person is "%d"\n,age)

}

Main
{

clrscr();

Person pete
pete.setage();
pete.showage();
getchar();
}

I think I have done well on my first program but I''m fast learner...as I''m deaf person myself...and what do u think of above code then?

This program above I using is boardland 1.0( I dont think I have spell it right)

Can anyone explain what class is as I like to know them more...

Thank for reading this

HOTSHOT

Share this post


Link to post
Share on other sites
You''re deaf? Cool, I''m deaf also! Nice knowing that I''m not the only deaf person in GD.net

Okay, classes (or structs, they''re both the same, except classes automatically have all of its members private, struct, public, unless you declare otherwise using private: and public are a group of members (variables, functions, etc) that is contained in one data. This is very handy for making games because you can declare a CPlayer with health, inventory, etc... Private members cannot be accessed outside the class, you have to access them via functions that is public.

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"

Share this post


Link to post
Share on other sites
I''m not an expert on class, but classes define objects. For example, you can have a class Car, and in Car, you would have methods for everything a car can do (start, move, crash, etc...) Realistically, I find myself using classes less for "tangible" things such as cars, and more for somewhat abstract things such as interfaces and sprites. But anyway, the beauty of using classes is that they are easy to maintain (at least in theory; some people might argue this, but I find them to be invaluable, myself) and are easily reusable as well. This isn''t so much an issue for games usually, but its a nice feature to have, in any case.

Share this post


Link to post
Share on other sites
A class is C++'s (and also Java's) mechanism for implementing the object oriented concept of encapsulation.

Ok, let's try that again in English.

Basically, classes let you define a type of object and all the operations and actions that are valid for that kind of object. Peon's car example is a good one. If you've ever used structs in C, classes are a very similar concept, except they can also contain functions (or more properly, methods) as well as data.

Classes also allow you to control who can access what. This is done with the keywords public, protected and private. Things declared in a public block can be accessed by anyone. Protected members of a class can only be accessed by that class and any class that's derived from that class. Private members can only be accessed by that class.

quote:
Original post by Peon
This isn't so much an issue for games usually, but its a nice feature to have, in any case.


I have to disagree with you here a little. The reusablility and maintainablity of classes are extrememly important in software as compilcated as games. The more help we can get, the better.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

[edited by - Chem0sh on June 25, 2002 11:54:28 PM]

Share this post


Link to post
Share on other sites
Chem0sh: Perhaps I''m thinking on too small a scale in that case; I don''t have ANY experience working on large projects. I meant it in that unlike programs like Windows, once a game is written, its not AS likely that the code will need to be reused. Some of it might be, if it''s effective, but I don''t think (keep in mind I''m just speculating here ) that the majority of code is reused in say, a sequel.

Share this post


Link to post
Share on other sites
As far as game specific code is concerned, you're probably right, Peon. Where reusability really comes in is with the engine (think Quake 2/3, Lithtech, etc). Writing an engine is a long, hard process (actually, I'm just now working on the one in ToTWGPG myself, but I've seen the full Quake 2 source). You want to squeeze as much use out of an engine as possible. Of course, by the time one would start working on the sequel, you'd probably want to have a new engine too. Anything you don't have to rewrite saves you time.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

[edited by - Chem0sh on June 26, 2002 6:11:15 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Zeraan
Private members cannot be accessed outside the class, you have to access them via functions that is public.

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"




tell him about my
friend 



Metal Typhoon



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"Did you learn C++?

We C++-Programmers, don''t use puts,scanf,printf!
Why dont you learn more bout iostream.h?"

we C++ programmers don''t use iostream.h either!
Why don''t you learn more bout iostream?

Share this post


Link to post
Share on other sites
Hiya all

quote:

"Did you learn C++?

We C++-Programmers, don''t use puts,scanf,printf!
Why dont you learn more bout iostream.h?"

we C++ programmers don''t use iostream.h either!
Why don''t you learn more bout iostream?
[/QUOTE]

Alright alright.......but I still learning on C++....u cantjust stick a knife at me cos I doing wrong......I''m learning for first C++...as I''m newbie c++.....just give me break....I will get there in the end...
I put # include < iostream.h > or iostream.h between in < >

I not trying to be nasty but I just trying my best here as I''M very greatful to see nice people helping me but what i dont like is....People who nasty to me....putting a big stick at me as newbie c++...as I could understand if I was very good at c++ and people say that is not c++ cos of puts,sanf, printf!

I''m easy going guys who what to say or not to say...I''m deaf person myself....as people got to understand what I say as my english is not bad but there u ago....

Thank for reading this....and also...I like to thank to all those people who help me ...I''m glad that I have found this site cos I did like to learn all those windows programs like rollercoaster tyoons game which is cool GUI!

Cheer all

HOTSHOT

Share this post


Link to post
Share on other sites
I''m not real familiar with friend command. I think it allows a class to access another class'' private members? Not sure about this.

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"

Share this post


Link to post
Share on other sites
quote:
Original post by Zeraan
I''m not real familiar with friend command. I think it allows a class to access another class'' private members? Not sure about this.


You''re right. You can also use it to allow individual functions access the class'' protected and private members.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

Share this post


Link to post
Share on other sites
hiya all


Let get this straight.....here the basic and c++


Basic c++

Global Public

Local Private


is this is right?

In programming basic.....global mean they can access all the function like public in c++ but for Local mean they only access some function and that will be private....

Can anyone clear up the questions I ask please as I do know lots about basic but I did like to know those c++ like publice and private!

Sorry about that!

HOTSHOT

Share this post


Link to post
Share on other sites
ok, to explain it a little more clearly, I''ll show you an example.

class SomeClass
{
public:
void someFunction();
void someAccesser();

int someData;

private:
int someAnotherData;
} SomeClassA;

to access your public members, you do this:

SomeClassA.someFunction();
SomeClassA.someAccesser(); //this does something with someAnotherData;

SomeClassA.someData = 6; //you can do this because its public, can be accessed outside of class

However, you CAN''T do this:

SomeClassA.someAnotherData = 7;

because it''s private and you will get compiler error. This helps you in organizing your code and make less bugs. To manipulate your private data, you need public functions like this:

void SomeClass::someAccesser()
{
someAnotherData++;
}

If you understand this, then you pretty much know one of the main features of C/C++.

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"

Share this post


Link to post
Share on other sites