tags:

views:

126

answers:

2

I'm very busy write now debugging some code, so I can't cookup a complete example, but this basically describes my problem

class Base{};
class MyX:public Base
{
  ...
};
class Derived:Base
{
  ...
};
template<class X>
class MyClass:Derived
{
private:
   MyClass(const MyClass& )
     :x()
   {}
public:
   MyClass(const X& value)
    :x(value)
   {}
};

....
MyX      x;
MyClass<MyX>(x);

This gives me an error like this:

error: there are two possible constrcutors MyClass<X>(const MyClass<X>&) and MyClass<X>(const X&)
A: 

I'm afraid you will have to give us a more complete code example. For instance, in constructor MyClass(const X&), you are initializing "x" with "x"?

MyClass(const& X value)
  :x(x)
Ferdinand Beyer
that was a typo, should've been value
Robert Gould
+5  A: 
MyClass<MyX>(x);

is parsed as

MyClass<MyX> x;

But MyClass<MyX> does not have a default constructor. Try giving it a name:

MyClass<MyX> p(x);
Johannes Schaub - litb