Results 1 to 5 of 5

Thread: How to create an Object in Arrays?

  1. #1
    Join Date
    Dec 2010
    Posts
    16

    How to create an Object in Arrays?

    Hello friends, I am bit confuse in Arrays in C++. It is very confusing; I am not able to understand how to create a object in array? Can we create the object first then use it? Is it compulsory to create the objects in arrays? If anyone is aware with this query then please let me know.

  2. #2
    Join Date
    May 2009
    Posts
    527

    Re: How to create an Object in Arrays?

    Array is a collection of similar data elements. To create more than one objects of a particular class the concept of array is used. The array of objects is created in very similar manner as we are creating the array of any data types. Array of objects is created at the end of class or in the main. In arrays you can create similar elements with same name which are in sequence.

  3. #3
    Join Date
    Apr 2009
    Posts
    488

    Re: How to create an Object in Arrays?

    This is the perfect example of creating a object in arrays. 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[3]; //array of objects
    }

  4. #4
    Join Date
    May 2009
    Posts
    539

    Re: How to create an Object in Arrays?

    You must remember that array of object is always created at the end of the class or you can also create it at the end of the main. Its upto to the code or, steps of execution in which you execute or fire your code. In the above code it is shown that the array of object is created at the end of main.

  5. #5
    Join Date
    May 2009
    Posts
    511

    Re: How to create an Object in Arrays?

    In the above example it first takes the input from length, breadth and height. Then, it calculates the operation which is given to the input. You will find that at the end at main function there is an object of an array made. This is quite easy to make where as you can also define and create the object of array at end of the class also. It is upto you, which you prefer. I don’t think that it is difficult to create and define an Array object.

Similar Threads

  1. How to create generic get object function in c++?
    By KADRI in forum Software Development
    Replies: 5
    Last Post: 27-03-2012, 11:35 PM
  2. How to create the XMLHttpRequest Object?
    By Bigga Lexx in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 07:34 PM
  3. How to create object in Autocad
    By InterMania in forum Windows Software
    Replies: 3
    Last Post: 30-10-2009, 11:26 PM
  4. How to create object in JAVA
    By HP_Crook in forum Software Development
    Replies: 3
    Last Post: 09-10-2009, 11:52 PM
  5. How many ways to create an object for class
    By Shanbaag in forum Software Development
    Replies: 3
    Last Post: 25-04-2009, 10:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,491,039.89661 seconds with 17 queries