Hello everybody!
This forum gave the greatest impression so congratulations to you folks who built it. I'm not an expert in c++, i've actually started learning a year ago so i need little help..I have two classes course and student. The course class is :

class course                                    
{
private :
   int a;
   float b;

public :
  course(int aa, int bb);

};

and the student class is

class student
{
private:
   int g;
  course p[10];
 public :
   constructor of student
};

My question is as you've already understood, how am i going to write the student constructor. The array of course instances confuses me...Any help would be appreciated..Thank you for reading my post..

vanalex

The constructor for student doesn't have to do anything at all with the array of courses because class course will take care of it. All student has to do is initialize its own variable g.

> The array of course instances confuses me...
there is nothing to get confused about; a c-style array of course instances cannot be created at all. reason: course does not have a default constructor.

To elaborate vijayan121s point; as I understand it, arrays of user declared type are constructed using the default constructor of the user defined type. If you don't declare a non-default constructor for your user defined type the compiler will declare a default constructor for you. However, if you declare a non-default constructor, as you have in the course class, then that service won't be done for you. In addition, the default constructor provided by the compiler may not meet the needs of the class. The lesson you should learn: always declare your own version of a default constructor for your user defined types.

hi!!! constructor has nothing to do with the array so dont be confused with it...
the constructor of student is
student()
{
}

like wise the constructor of course is
course()
{
}

the above constructor which mentioned above is a default construtor..
this is a multiple argument constructor

course(int aa, int bb);
which is described as
course(int aa,int bb)
{
AA=aa;
BB=bb;
}

yes, you need to code a default constructor for course so that the class variables get initialized. If you don't code it the default constructor won't do it either.

class course                                    
{
private :
   int a;
   float b;

public :
  course(int aa, int bb);
  course() {a = 0; b = 0.0F; } // <<<<< add this to your class

};

hi!!! constructor has nothing to do with the array so dont be

Of course it does! The course constructure of each array element will be called when the student class is instantiated.

in course p[10];

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.