class and objects

how can use class and objects in c++

Page 1 of 1

3 Replies - 839 Views - Last Post: 29 February 2008 - 03:23 AM Rate Topic: -----

#1 mikka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-February 08

class and objects

Posted 26 February 2008 - 12:58 AM

pls tell me use of objects and class in c++
Is This A Good Question/Topic? 0
  • +

Replies To: class and objects

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: class and objects

Posted 26 February 2008 - 01:14 AM

Welcome to </dream.in.code> mikka, glad you could make it! Hope to see you around the forums someday :)

This is a question that should be asked in the C/C++ Forum whrer it will get attention from those experts. This particular forum is for introductions only :)

Happy Coding!
Was This Post Helpful? 0
  • +
  • -

#3 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 731
  • View blog
  • Posts: 8,644
  • Joined: 14-September 07

Re: class and objects

Posted 26 February 2008 - 06:46 AM

Welcome to Dream In Code! Hope to see you around the forums.
Was This Post Helpful? 0
  • +
  • -

#4 friendster2  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 244
  • Joined: 29-February 08

Re: class and objects

Posted 29 February 2008 - 03:23 AM

What is a class?

The fundamental building block of OO software.

A class defines a data type, much like a struct would be in C. In a computer science sense, a type consists of both a set of states and a set of operations which transition between those states. Thus int is a type because it has both a set of states and it has operations like i + j or i++, etc. In exactly the same way, a class provides a set of (usually public) operations, and a set of (usually non-public) data bits representing the abstract values that instances of the type can have.
What is an object?

A region of storage with associated semantics.


You can use your class like this:
Declare an object of the class containing the public members of your class.

CMyClass objMyClass; // create a object of the class


class CMyClass
{
public: // public members

CMyClass(); // constructur allways same name as the class
~CMyClass(); // destructor ~ + class name (often created virtual)

private; // private members

};


The other class is a little bit more advanced it has got a class constructor
(init function) and class destructor (destroy function). We use new to create
a new instance of this class, lik this:

CMyClass *objMyClass = new CMyClass;

If we use new and store it in the free memory we must always remember to
destroy the object with delete to make sure you free the memory, like this:

delete [] objMyClass;

You might not see the use of classes right away if you just started programming.
I know I didn't.. But once you get used to them, they make things simpler.

An example of what a class can be used for:
Have you ever played a computer game like Zonic or Super Mario?
You might have noticed that the plot of the game is collecting coins..
If you create a class for drawing one coin, you can also use this class for
drawing 100 coins, lik this: CCoin objCoin[100];
Now you have got 100 coins instead, and you just write the code for one coin..

*/

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1