Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 29-12-2010
Member
 
Join Date: Mar 2010
Posts: 393
How Objects of class are created in C++?

I am having a problem in creating object of class in C++. I want to know how to create it? As, it is the base of the programming language which is not only used in C++ but it is used in every programming language. So, I am desperately willing to know the solution to this question. IF anyone having any information about it then please let know as soon as possible.
Reply With Quote
  #2  
Old 29-12-2010
Member
 
Join Date: May 2009
Posts: 620
Re: How Objects of class are created in C++?

You should know that class is user defined data type which encapsulates data and member function together. The objects are the run time entity. It has the physical existence. The object of the class is created in a very similar way as we create the variable of any built in data type(like int ,float).
The Object is created by writing the name of the class followed by the name of the object. More than one Object can be created on the same line or separate line.
The general syntax is

classname objectname1,objectname2?;
Reply With Quote
  #3  
Old 29-12-2010
Member
 
Join Date: May 2009
Posts: 523
Re: How Objects of class are created in C++?

Code:
For Example
Box b1,b2;

Here b1 and b2 are the objects of class Box.

For example
class Box
{
 private :   int l,h,w;

public :

void get_data()
{
cout<<”enter the length width and height of box”;
cin>>l>>h>>w;
}

void display()
{
cout<<”the length of box is<<l;
cout<<”the height of box is<<h;
cout<<”the width of box is<<w; 
}
};

main ()
{
Box b1,b2;
}
In above example b1 and b2 are the two objects of the class Box. Here the object b1 and b2 both have their own copy of variables l, h, w ,and created on the same line. The Object can be created on separate line
Box b1;
Box b2;
There is another place where objects can be created i.e. at the time of defining a class by placing objects name after the ending brace but before the semicolon of class.

class Box
{
members
}b1,b2;
Reply With Quote
  #4  
Old 29-12-2010
Member
 
Join Date: Apr 2009
Posts: 567
Re: How Objects of class are created in C++?

Well, you should know that when you are creating a class you should be aware that it should follow the class of the object. This is very much important when objects of class are created in the class. Well, many of them get confused while creation of object. The best part is that you can create one object or more than that in same or separate line.
Reply With Quote
  #5  
Old 29-12-2010
Member
 
Join Date: May 2009
Posts: 532
Re: How Objects of class are created in C++?

It is important to know how object of class are created in the class because if you are not able to create a object in class then how would you able execute or write the code for different functions where in creation of object is must. So, one gets struck when is not able to do so. I think that you can go through the above example which can help you to understand this term better.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How Objects of class are created in C++?"
Thread Thread Starter Forum Replies Last Post
Upgrade Sony Ericsson Xperia Play Micro SD card from class 2 8GB to class 4 32GB Aaryan2011 Portable Devices 8 08-10-2011 11:06 PM
Instantiate different objects of same class ISAIAH Software Development 5 09-03-2010 10:05 AM
Accessing Objects Outside Of Class Level8 Software Development 4 22-02-2010 08:22 PM
How to sort vector objects by class member variables in c++? Linoo Software Development 4 29-01-2010 07:15 PM
Good news for CBSE CLASS X & CLASS IX - visit learnnext surya_expert Education Career and Job Discussions 0 13-12-2008 12:09 PM


All times are GMT +5.5. The time now is 09:59 PM.