Boost.Parameter: copy constructor gets "mistaken" for constructor(const ArgPack& ) in parent class.
Hello, I have a situation which I can summarize as: #include <boost/parameter/keyword.hpp> #include <boost/parameter/name.hpp> #include <boost/parameter/parameters.hpp> #include <boost/parameter/preprocessor.hpp> BOOST_PARAMETER_KEYWORD(tag, xx) struct A{ template<typename ArgPack> A(const ArgPack& arg):x_(arg[xx|0]){} A(const A&){} A& operator=(const A& that){ if(&that!=this){ x_ = that.x_; return *this; } } unsigned x_; }; 3 copy constructors are shown below, on the last of which works. However it's really the first one that I'd like to get to work. struct B : public A{ template<typename ArgPack> B(const ArgPack& arg):A(arg){} B& operator=(const B& that){ if(&that!=this){ A::operator=(that); return *this; } } //B(const B& that):A(that){} //no match for 'operator[]' in 'arg[(+<unnamed>::xx)->boost::parameter::keyword<T>::operator| [with Default = int, Tag = tag::xx](((const int&)((const int*)(&0))))]'| //B(const B& that):A(static_cast<A>(that)){} //fails too B(const B& that):A((xx=that.x_)){} //requires knowledge of A's members, not satisfactory. }; Any suggestion, please?
AMDG er wrote:
3 copy constructors are shown below, on the last of which works. However it's really the first one that I'd like to get to work.
struct B : public A{ template<typename ArgPack> B(const ArgPack& arg):A(arg){}
B& operator=(const B& that){ if(&that!=this){ A::operator=(that); return *this; } }
//B(const B& that):A(that){} //no match for 'operator[]' in 'arg[(+<unnamed>::xx)->boost::parameter::keyword<T>::operator| [with Default = int, Tag = tag::xx](((const int&)((const int*)(&0))))]'|
//B(const B& that):A(static_cast<A>(that)){} //fails too
This is almost right. Cast to const A& instead of A. In Christ, Steven Watanabe
Steven Watanabe wrote:
AMDG
er wrote:
3 copy constructors are shown below, on the last of which works. However it's really the first one that I'd like to get to work.
struct B : public A{ template<typename ArgPack> B(const ArgPack& arg):A(arg){}
B& operator=(const B& that){ if(&that!=this){ A::operator=(that); return *this; } }
//B(const B& that):A(that){} //no match for 'operator[]' in 'arg[(+<unnamed>::xx)->boost::parameter::keyword<T>::operator| [with Default = int, Tag = tag::xx](((const int&)((const int*)(&0))))]'|
//B(const B& that):A(static_cast<A>(that)){} //fails too
This is almost right. Cast to const A& instead of A.
In Christ, Steven Watanabe
Thanks!
participants (2)
-
er
-
Steven Watanabe