#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    16
    Rep Power
    0

    Passing Array of Object gives compilation ERROR


    Passing Array of Object gives compilation ERROR

    Hello Everybody

    This is my question
    Define a class named HOUSING in C++ with the following descriptions:
    Private members
    REG_NO integer(Ranges 10 1000)
    NAME Array of characters(String)
    TYPE Character
    COST Float
    Public Members
    Function Read_Data( ) to read an object of HOUSING type
    Function Display() to display the details of an object
    Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING Use random function to generate the registration nos. to match with REGNO from the array.

    Now I'm trying to do this by this way

    Code:
          #include <iostream.h>
          #include <conio.h>
          #include <stdlib.h>
        
          class housing
          {
                private:
                    int REG_NO;
                    char NAME[10];
                    char TYPE;
                    float COST;
                public:
                    void Read_Data();
                    void Display();
                    void DrawNos(housing);
          };
          void housing::Read_Data( )
          {
                cout<<"Enter Registration No: ";
                cin>>REG_NO;
                cout<<"Enter Name: ";
                cin>>NAME;
                cout<<"Enter Type: ";
                cin>>TYPE;
                cout<<"Enter cost: ";
                cin>>COST;
          }
          void housing::Display()
          {
          }
          void housing::DrawNos(housing* h1[])
          {
               int N=10;
               int randomREG=random(10);
               N=random(2);
               cout<<h1[N]->REG_NO;
          }
          void main()
          {     
                int i=0;
                housing* h[5];
                for(i=0;i<5;i++)
                {
                        h[i]->Read_Data();
                }
                for(i=0;i<5;i++)
                {
                        h[i].DrawNos(h); // I am trying to pass the array of object to DrawNos function but getting error
                }
          }
    I am tryin to pass the entire array of object in DrawNos(). but getting comilation error -

    32: 'housing::DrawNos(housing * *)' is not a member of 'housing'
    48: Structure required on left side of . or .*
    What is the problem? How can I pass the array of object in function and use it.

    Please help me with this problem.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Santa Claus makes an early start with distributing gifts here and there
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo