
Hi folks, In the example below, while (1) is compiling fine, (2) causes compiler error in linux gcc 4.1.3. I certainly don't want to copy the member variable of the object in copy constructor, and I need T2. How can I handle it? Thanks, emre #include <boost/noncopyable.hpp> struct A: boost::noncopyable { }; template <typename T> struct B { B() { } B(const B<T>& b) { } // (1) template <typename T2> B(const B<T2>& b) { } // (2) private: T a; }; int main() { B<A> b1; B<A> b2(b1); }

On Tue, Apr 15, 2008 at 5:38 AM, Emre Turkay <emreturkay@gmail.com> wrote:
Hi folks,
In the example below, while (1) is compiling fine, (2) causes compiler error in linux gcc 4.1.3. I certainly don't want to copy the member variable of the object in copy constructor, and I need T2. How can I handle it?
[snip]
B(const B<T>& b) { } // (1) template <typename T2> B(const B<T2>& b) { } // (2)
Without (1), you'll be using the (implicit) default copy constructor, which takes precedence over (2) and will attempt to copy A. You need both copy constructors for this. - Jim
participants (2)
-
Emre Turkay
-
James Porter