This code will fail with error message (line numbers are off). How do I fix this (keeping same intent)?
g++ -o c_test c_test.cpp
c_test.cpp: In function 'int main(int, char**)':
c_test.cpp:28:18: error: no matching function for call to 'wcalc(CWrapped<5>::u_type&)'
c_test.cpp:28:18: note: candidate is:
c_test.cpp:17:58: note: template int wcalc(typename CWrapped::u_type)
The wrapped type is passed to both "calc" and "wcalc" function, but the 2nd one fails. I want to be able to wrap the types so I can use a compile-time define to specify different types but still use the same wrapped function
// Example template class
template <int T_B>
class m_int {
public:
int x;
m_int() { x = T_B; }
int to_int() { return(x); }
};
// Desired Typedef wrap
template <int T_BITS> struct CWrapped {
typedef m_int<T_BITS> u_type;
};
// This is ok, no wrapping
template <int T_BITS> int calc(m_int<T_BITS> x) {
return(x.to_int());
}
// This fails when instantiated
template <int T> int wcalc(typename CWrapped<T>::u_type x) {
return(x.to_int());
}
int main(int argc, char* argv[]) {
CWrapped<5>::u_type s;
int x = calc(s);
int y = wcalc(s);
return(0);
}