O
Olaf
Hi,
I'm working on a thin libcurl layer. Therefore I have the following classes:
template<typename T, long CURLOPT_ID>
class CurlOption: boost::noncopyable {
public:
typedef typename boost::call_traits<T>:aram_type param_type;
....
public:
// constructors:
CurlOption() {}
CurlOption(param_type v) : m_value(v) {}
public:
long option() const { return CURLOPT_ID; }
result_type parameter() { return m_value; }
void setopt(CURL* handle);
private:
value_type m_value;
};
and the specialized for the templated arguments T (ether bool, long,
std::string etc.):
template<long CURLOPT_ID>
class CurlOption<bool, CURLOPT_ID> {
public:
void setopt(CURL* handle) {
curl_easy_setopt(handle,
this->option(), this->value() ? 1 : 0);
}
};
e.g. used like
struct CurlOpt {
typedef CurlOption<bool, CURLOPT_VERBOSE> Verbose;
};
and than the cURL handle class self using a double dispatch approach:
class EasyCurl : boost::noncopyable
{
public:
...
template<typename T, long ID>
void setopt(const CurlOption<T, ID>& opt) {
opt.setopt(m_curl);
}
private:
CURL* m_curl;
};
By use of this, e.g.
CurlOpt::Verbose v(on);
I get a compiler error:
EasyCurl.cpp: In member function »void EasyCurl::setVerbose(bool)«:
EasyCurl.cpp:124: Fehler: keine passende Funktion für Aufruf von
CurlOption<bool, 41l>::CurlOption(bool&)«
EasyCurl.hpp:19: Anmerkung: Kandidaten sind: CurlOption<bool,
41l>::CurlOption()
EasyCurl.hpp:19: Anmerkung: CurlOption<bool, 41l>::CurlOption(const
CurlOption<bool, 41l>&)
Obviously the right ctor is missing. Anyway, do I have all the stuff
from the Template (typedefs including) to rewrite for the specialized
template class? Or is there another way? I thought I need only to
overwrite the specialized members - where is my mistake? Is there a
better and correct way?
Thanks
Olaf
I'm working on a thin libcurl layer. Therefore I have the following classes:
template<typename T, long CURLOPT_ID>
class CurlOption: boost::noncopyable {
public:
typedef typename boost::call_traits<T>:aram_type param_type;
....
public:
// constructors:
CurlOption() {}
CurlOption(param_type v) : m_value(v) {}
public:
long option() const { return CURLOPT_ID; }
result_type parameter() { return m_value; }
void setopt(CURL* handle);
private:
value_type m_value;
};
and the specialized for the templated arguments T (ether bool, long,
std::string etc.):
template<long CURLOPT_ID>
class CurlOption<bool, CURLOPT_ID> {
public:
void setopt(CURL* handle) {
curl_easy_setopt(handle,
this->option(), this->value() ? 1 : 0);
}
};
e.g. used like
struct CurlOpt {
typedef CurlOption<bool, CURLOPT_VERBOSE> Verbose;
};
and than the cURL handle class self using a double dispatch approach:
class EasyCurl : boost::noncopyable
{
public:
...
template<typename T, long ID>
void setopt(const CurlOption<T, ID>& opt) {
opt.setopt(m_curl);
}
private:
CURL* m_curl;
};
By use of this, e.g.
CurlOpt::Verbose v(on);
I get a compiler error:
EasyCurl.cpp: In member function »void EasyCurl::setVerbose(bool)«:
EasyCurl.cpp:124: Fehler: keine passende Funktion für Aufruf von
CurlOption<bool, 41l>::CurlOption(bool&)«
EasyCurl.hpp:19: Anmerkung: Kandidaten sind: CurlOption<bool,
41l>::CurlOption()
EasyCurl.hpp:19: Anmerkung: CurlOption<bool, 41l>::CurlOption(const
CurlOption<bool, 41l>&)
Obviously the right ctor is missing. Anyway, do I have all the stuff
from the Template (typedefs including) to rewrite for the specialized
template class? Or is there another way? I thought I need only to
overwrite the specialized members - where is my mistake? Is there a
better and correct way?
Thanks
Olaf