[ROOT] template constructor

From: Troy D. Straszheim (troy@ifh.de)
Date: Sun Feb 29 2004 - 04:57:08 MET


Hey rooters -

How about this: I would like to allow automatic type conversion via
constructor.

With these classes:

struct C { };

struct A {
  A() { };

  template <class U>
  A(const U& u) { cout << __PRETTY_FUNCTION__ << endl; }

  template <class U>
  void doit(const U& u) { cout << __PRETTY_FUNCTION__ << endl; }
};

And the following linkdef:

#pragma link C++ class A+;
#pragma link C++ class C+;
#pragma link C++ function A::A(const C&);
#pragma link C++ function A::doit(const C&);

My sesson reports the following:

root [0] C c;
root [1] A a;
root [2] a.doit(c);
void A::doit(const U&) [with U = C]
root [3] A a2(c);
Error: Can't call A::A(c) in current scope FILE:(tmpfile) LINE:1
Possible candidates are...
filename       line:size busy function type and name  (in A)
(compiled)        0:0    0 public: A A(void);
(compiled)        0:0    0 public: A A(const A&);

The template function doit() works, but the copy constructor does not.  Any ideas?

Cheers,

Troy Straszheim



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET