array works with constructor with arguments

hi experts,
today i meet a new problem,
if i have a class and constructor with arguments,
example:
1
2
3
4
5
6
7
8
9
10
class student{
private:
 int ID;
 string name:
public:
 student(int a, string b){
  ID=a;
  name=b;
 }
};


Now in my main function how i delay a array of student and set value without using other method to do it? As u know, normally i will create a method like setStudent to set the value, but now i wonder can i do it with constructor?
then what i gonna write in my main?
example: (WRONG CODEEEE)!!
 
student mike[2]={mike[0](10,m), mike[1](11,f)}


thx for the time for reading...
I think that would probably be:

 
student mike[] = { student(10, m), student(11, f) };


Invoking student() creats an object of type student and you want to create an array of objects of class student.
There is also a typo in your declaration. There is a colon rather than a semi-colon after the name attribute. That should cause major problems.

1
2
3
4
// A better way to do the constructor in this case.
student(int a, const string& b) : ID(a), name(b) 
{
}
wow..
Galik, thx for the help!
it solved my problem.
and kempo, thx for the comment also.. i never know there is such way to declare constructor..
guess I have learn a new thing!! THX ALOT!!
thank you
very good
Topic archived. No new replies allowed.