I was attempting to template a C++ function but one of the templated structure's members isn't being recognized. My code is as follows:
template<typename Tins, typename Tgload>
Tgload getreflection_terminated_twoport(const Tins &S, const Tgload &gammaload,bool loadport2)
{
paramatrix S2p; // S-parameters 2x2 matrix of the two-port
if(typeid(Tins)==typeid(std::pair<double,paramatrix>))
{
S2p=S.second;
}
else if(typeid(Tins)==typeid(paramatrix))
{
S2p=S;
}
else
{
std::cout<<"ERROR in getreflection_terminated(): invalid type for 2-port S-parameters"<<std::endl;
exit(10);
}
}
I get a compiler error on the line containing S2p=S.second and the compiler complains that S has no member second.
However one possibility of typename Tins Does have a member second as part of a pair.
I would have thought that the compiler would have recognized, from the
if(typeid(Tins)==typeid(std::pair<double,paramatrix>))
statement, that S could have a member second since
std::pair<double,paramatrix>)
does have a member second.
Why this doesn't work? and whether I can use such datatypes as template options?
I'm new to using templates and I've not been able to find an answer to this.