pls tell me use of objects and class in c++
class and objectshow can use class and objects in c++
Page 1 of 1
3 Replies - 596 Views - Last Post: 29 February 2008 - 03:23 AM
Replies To: class and objects
#2
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!
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!
#3
Re: class and objects
Posted 26 February 2008 - 06:46 AM
Welcome to Dream In Code! Hope to see you around the forums.
#4
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..
*/
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..
*/
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|