I have a generic class defined down below,
with member parameter an array, i.e. T grades[5];
when I declare object of this class, using
StudentRecord<int> srInt();
and then call a member function of the class, using
srInt.setGrades(arrayInt);
I get an error,
error: request for member ‘setGrades’ in ‘srInt’, which is of non-class type ‘StudentRecord<int>()’
srInt.setGrades(arrayInt);
but when i declare class using(below), and try to call same function, it works
StudentRecord<int> srInt;
//header file for main.cpp
#include<iostream>
using namespace std;
const int SIZE=5;
template <class T>
class StudentRecord
{
private:
const int size = SIZE;
T grades[5];
public:
void setGrades(T* input);
};
template<class T>
void StudentRecord<T>::setGrades(T* input)
{
for(int i=0; i<SIZE;++i)
{
grades[i] = input[i];
}
}
My question is there any difference between declaring class,
StudentRecord<int> srInt();
v/s
StudentRecord<int> srInt;