How to create objects from a derived class

I'v just stated working on derived classes
first i created the person in my program and then the derived class , " student " and i now i don't know how to create objects which belongs to the student class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    /////// .h  ///////
 [code]#pragma once
#include "person.h"
class Student :public Person
{
public:
	Student(int ,string,string,int,double);

	void setInfo(string,string,int,double);
	void getInfo();

	int getID();

	void setAverage(double);
	double getAverage();
private:
	const int ID;
	double Average;
};
//////////// .cpp////////////
#include "Student.h"

void Student::setInfo(string n,string f,int a,double avg)
{
	setName(n);
	setFamily(f);
	setAge(a);
	setAverage(avg);
}
void Student::getInfo()
{
	cout<<ID<<'\t'<<Name<<'\t'<<Family<<'\t'<<Age<<'\t'<<Average<<endl;
}
int Student::getID()
{
	return ID;
}
void Student::setAverage(double avg)
{
	Average=avg;
}
double Student::getAverage()
{
	return Average;
}

Last edited on
Instantiating a derived class is no different that instantiating an object of any other class
 
  Student Fred ( /* arguments to Student constructor */ );  // Create a Student instance 


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
ok
sure
thank you
Topic archived. No new replies allowed.