Re: Problem with partial specialized member functions
Usually I like to look at my references since my long term memory is
swiss cheese.. but
//Helper Template class
template <typename T>
struct Type2Type
{
typedef T OrigType;
};
//Generic Implementation
template <class U, class T>
T* Foo(const U& arg, Type2Type<T>)
{
return new T(arg);
}
//Partial Specialization
template <class U>
Bar* Foo(const U& arg, Type2Type<Bar>)
{
return new Bar(arg);
}
// Usage
String* pStr = Foo("Hello", Type2Type<String>());
Bar* pBar = Foo(1, Type2Type<Bar>());
Thank you; did I right understand you? Unfortunately my code doesn't
compile:
typedef CurlOption<bool, CURLOPT_VERBOSE> Verbose;
class EasyCurl : boost::noncopyable {
private:
template<typename T> struct dispatch { };
template<typename T, long ID> // L342, below L343
void setopt(const CurlOption<T, ID>& opt, dispatch<T>);
[..]
public:
template<typename T, long ID>
void setopt(const CurlOption<T, ID>& opt) { // L357
setopt(opt, dispatch<T>());
}
};
template<typename T, long ID>
inline // L394, below L395
void EasyCurl::setopt(const CurlOption<bool, ID>& opt, dispatch<bool>) {
curl_easy_setopt(m_curl, opt.option(), opt.value() ? 1 : 0);
}
The errors are:
EasyCurl.hpp:395: Fehler: Prototyp f?r ?void EasyCurl::setopt(const
CurlOption<bool, ID>&, EasyCurl::dispatch<bool>)? passt zu nichts in
Klasse ?EasyCurl?
EasyCurl.hpp:357: Fehler: Kandidaten sind: template<class T, long int
ID> void EasyCurl::setopt(const CurlOption<T, ID>&)
EasyCurl.hpp:343: Fehler: template<class T, long int ID>
void EasyCurl::setopt(const CurlOption<T, ID>&, EasyCurl::dispatch<T>)
EasyCurl.hpp:395: Fehler: Template-Definition eines Nicht-Templates
?void EasyCurl::setopt(const CurlOption<bool, ID>&,
EasyCurl::dispatch<bool>)?
Thanks,
Olaf