LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-21-2005, 02:51 PM   #1
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
Possible uses for classes.


I just about completely understand how a class works, and already I think I would know how to use it, in lets say a game...

class Player
{
string playername;
int playerhealth;
public:
void stats(char,int);
}

void Player::stats(string a, int b)
{
playername = a;
playerhealth = b;
}

int main()
{
Player pa, pb;
pa.stats("p1",100);
pb.stats("p2",100);
return 0;
}

... from what I see, it could be usefull. But I would like to know other situations where the classes will/may come in handy.
 
Old 11-21-2005, 02:57 PM   #2
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Rep: Reputation: 15
This is just what I've come to conclude so far in my own personal experience:

Classes are used as organization in programming, so that you don't have 100000000 functions in one file, and helps you organize with respect to the purpose of the functions by separating them into class files.

In object oriented programming, however, some languages allow you make objects from classes, so you could have an array of Players, from the example you posted, where you could have any number of players playing a game, while keeping track of each of the Players attributes.

Classes are sort of like paragraphs in a paper. You'd never know what the hell was going on if you didn't add a space and an indent mark after your thought was finished

Enjoy.

Mistro116
 
Old 11-21-2005, 05:12 PM   #3
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
>> Classes are sort of like paragraphs in a paper. You'd never know what the hell was going on if you didn't add a space and an indent mark after your thought was finished

Classes are more like a paragraphs in a book that once the first page is written, the paragraphs can then go on to write themselves, and also spellcheck, publish and then buy themselves.

You are on the right track.. keep reading and writing and you will soon grasp the entire concept of why. The toughest part of learning C++ is not the actual syntax, it is getting your head wrapped around OOP and the reasons and possibilities.
 
Old 11-21-2005, 07:06 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Classes define the strucure and methods of a possible object.
An object is an instantiation of of a class def.
To put that another way, classes are like a struct def in C, but you have to create (instantiate) a usable copy (object) to do anything with it.
 
Old 11-21-2005, 10:10 PM   #5
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
Thanks you guys, because of you guys/gals, I've been graspin c++ more thoroughly whenever I ask a question here. I'm confident if I look at something in different paradimes I soon become a full C++ pro..grammer. :P
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Classes in VC++ Diederick Programming 2 11-30-2005 10:57 AM
classes in C++ niteshadw Programming 2 07-05-2005 07:05 PM
C++ nested classes enemorales Programming 5 05-23-2005 03:40 PM
RHCE Classes ninjaz Linux - Certification 3 05-03-2005 04:23 PM
OOP (PHP) classes and extended classes ldp Programming 3 03-05-2005 11:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration