Thread: Need basic information about Constructors!

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    230

    Need basic information about Constructors!

    How can i initialize an array (maxsize: 4), (type: class Employee), so as i can get for 4 people their names, ages, etc. ?

    Code:
    class Employee{
    	private:
    		string AFM;
    		string name;
    		string surname;
    		
    		int age;
    		float salary;
    	public:
    		Employee(); // Constructor!
    		int read();
    		void show();
    		class Employee A[4];
    };
    Also, as you can see i am using a constructor here(it' s my first time) but i do not know what to write in main... My first thought was something like this, but i am sure that it is wrong(a, b c, d are the 4 people!)!

    What shall i write here to finally create the array i wanted ?
    Code:
    int main(){
    	Employee a, b, c, d;
    		a.read();
    		b.read();
    		c.read();
    		d.read();		
    return 0;
    }
    thank you all!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    In your class the line you have highlighted does not belong there.

    In main is where you setup your Employee array.

    Code:
       Employee A[4];  // Declare an array of Employee.

    Jim

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    Quote Originally Posted by jimblumberg View Post
    In main is where you setup your Employee array.

    Code:
       Employee A[4];  // Declare an array of Employee.
    Jim
    Everything i need to construct an Array type class Person is the above code(only)? Where shall i declare that A array is an Array?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Where shall i declare that A array is an Array?
    Perhaps a review of what an array is might be in order. See this link: Arrays.

    Also I presume that you have your class member functions written and just did not show them.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Programm giving Error
    By dharmil007 in forum C Programming
    Replies: 16
    Last Post: 05-27-2010, 02:01 PM
  2. Replies: 29
    Last Post: 10-22-2009, 11:01 AM
  3. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  4. Copy constructors and private constructors
    By Eibro in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2002, 10:16 AM
  5. using information from an array
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 12-07-2001, 05:30 PM