Fun with templates
I've not had too much experience with templates and now I have a problem that I can't figure out. If you could please help me, that would be wonderful!
I have the following casting operator inside a templated class and its implementation:
What I'm effectively trying to do is to be able to use such syntax as (atomic_time<GPS>)TAItime (where TAItime is an atomic_time) with the above. However, that bit of code, when placed in a program, produces the following compilation error:
I know what the above error means and I'm just damn confused, because it shouldn't be needing to construct one type of atomic_time from another in the above cast. In fact, the cast should return the correct type of atomic_time (GPS in this case). But it isn't...
Can anyone see where I'm going wrong?
I have the following casting operator inside a templated class and its implementation:
template<typename T>
class atomic_time
{
...
template<class Y>
operator atomic_time<Y>();
...
};
template<class T> template<class Y>
atomic_time<T>::operator atomic_time<Y>()
{
atomic_time<Y> newtime( GetSecs(), GetNanoSecs() );
timespan ts = Timescale().GetOffset( newtime.Timescale() );
newtime += ts;
std::cout << "Performed cast" << std::endl;
return newtime;
}
What I'm effectively trying to do is to be able to use such syntax as (atomic_time<GPS>)TAItime (where TAItime is an atomic_time
testsuite.cpp: In function 'int main(int, char**)':
testsuite.cpp:95: error: call of overloaded 'atomic_time(astrotime::atomic_time<astrotime::TAI>&)' is ambiguous
../astrotime/atomic_time.h:134: note: candidates are: astrotime::atomic_time<T>::atomic_time(const astrotime::atomic_time<T>&) [with T = astrotime::GPS]
../astrotime/atomic_time.h:128: note: astrotime::atomic_time<T>::atomic_time(int) [with T = astrotime::GPS]
../astrotime/atomic_time.h:114: note: astrotime::atomic_time<T>::atomic_time(double) [with T = astrotime::GPS]
make: *** [testsuite] Error 1
I know what the above error means and I'm just damn confused, because it shouldn't be needing to construct one type of atomic_time from another in the above cast. In fact, the cast should return the correct type of atomic_time (GPS in this case). But it isn't...
Can anyone see where I'm going wrong?
