Re: single function with a multiple-type parameter
Luigino wrote:
Hmmmm.....
Doesn't work even if I use different class for each parameter...
template<class T1, class T2, class T3>BOOL MyWriteFunction(T1&
f1_entry1, T2& f1_entry2, T3& f1_retvalue);
template<class T4, class T5, class T6>BOOL MyReadFunction(T4&
f2_entry1, T5& f2_entry2, T6& f2_retvalue);
if ( MyReadFunction(a_entry1, a_entry2, m_returnValue) ) ......
it goes saying:
error LNK2019: unresolved external symbol "public: int __thiscall
MyReadFunction<class ATL::CStringT<wchar_t,class
StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > >(wchar_t
const *,wchar_t const *,class ATL::CStringT<wchar_t,class
StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > &)" (??
$MyReadFunction@V?$CStringT@_WV?$StrTraitMFC@_WV?
$ChTraitsCRT@_W@ATL@@@@@ATL@@@CAnalyzer_Common@@QAEHPB_W0AAV?
$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z)
referenced in function "protected: virtual int __thiscall OnInitDialog
(void)" (?OnInitDialog@....@@MAEHXZ)
The fact is inside function I'm just using CSettingsStore to store
data in the registry, so since I could store integers or strings I can
call the same Read() or Write() method which has different
implementations for same function so doing a single call to
MyReadFunction I could read both a string or an integer...
Shall I missed something for this?...
Luigi:
Unlike their non-template counterparts, the definitions of template functions
and methods must be present in the header file. You should not use a separate
..cpp file for the implementations.
Normally, this would violate the one-definition rule, but not for template
functions and methods.
--
David Wilkinson
Visual C++ MVP