#include <iostream>
#include <string>
usingnamespace std;
template< class T >
class Employee{
private:
T EmployeeID , EmployeeSalary;
public:
T Employee( T theID , T theSalary ){
EmployeeID = theID;
EmployeeSalary = theSalary;
}
};
template< class T >
class Student{
private:
public:
T Student(){}
};
int main(){
Employee <> theEmployee( 2 , 3000 );
Student <> theStudent ();
system( "pause" );
return 0;
}
And here is the question given Create a class template for a class that holds an object and the number of data elements in the object. For example, if an Employee class has two data elements, an ID number and a salary, then the class template holds the number 2 and an Employee object; if a Student class contains 12 data elements, then the class template holds 12 and a Student object. Write the code for standard input function for the object that displays a message on the screen – “You will be ask to enter X items” – where X is the number of data elements. Write a main() function that tests your template class with an integer and two programmer-defined classes
So can i ask that , am i do correctly so far?
what is the mistake i made ?
constructors dont return anything, when declaring variable of a template class you need to pass the type to it Employee <> theEmployee( 2 , 3000 ); should look something like Employee <int> theEmployee( 2 , 3000 );
Number 1: you should remove return type from constructor of first class. because constructor returns nothing.
Number 2: specify data type in main function when instantiating the template based classes.
ENJOY!!!
okay. i changed it . i get what he mean .
but now if a Student class contains 12 data elements, then the class template holds 12 and a Student object. Write the code for standard input function for the object that displays a message on the screen – “You will be ask to enter X items” – what mean for this sentences?
how should the class Student pass the parameter to constructor? abit blur with it