I have this template function and class in mc.h/mc.cpp files:
template <class MemT>
class MC;
template <class MemT>
MemT & getMCObj(int t_instNum);
class HBM;
template <class MemT>
class MC
{
public:
MC(){}
friend MemT & getMCObj<MemT>(int t_instNum);
private:
MemT memTobjList[12];
};
class HBM
{
public:
bool someFunc();
private:
int num_inst;
};
In the cpp file I have
template<class MemT>
MemT & getMCObj(int t_instNum)
{
return MC<MemT>::memTobjList[t_instNum];
}
bool HBM::someFunc()
{
num_inst = 1;
}
In main:
int main()
{
MC<HBM> mC;
HBM & ptr = getMCObj<HBM>(3);
ptr.someFunc();
return 0;
}
I get this error when I compile: main.cpp:8: undefined reference to `HBM& getMCObj(int)'
I can't seem to figure out whats going wrong. Whats the issue here?
Thanks.
Aucun commentaire:
Enregistrer un commentaire