A
Alexander Stippler
Hi
I have already posted and discussed the following problems once, but
despite really helpful hints I did not get any further with my problem
(I at least learned, first to exactly consider why something does not
work instead of immediately searching for work arounds) . I have the
following code resulting in an ambiguity:
--------------------------------------------------------
template <typename Impl>
class Vector {};
template <typename Ref>
class VectorView : public Vector<VectorView<Ref> >
{
public:
operator const Ref &() const { return _ref; }
private:
Ref _ref;
};
template <typename T>
class DenseVector : public Vector<DenseVector<T> >
{
public:
DenseVector() {}
template <typename Impl>
DenseVector(const Vector<Impl> &rhs) {}
int amin(const DenseVector<double> &x) { return 1; }
int amin(const DenseVector<float> &x) { return -1; }
int main()
{
DenseVector<double> x;
int i = amin(x(1,3));
}
--------------------------------------------------------
Some things are not really clear to me:
1) what causes the ambiguity. The conversion operator in
class VectorView returns a DenseVector<double>. Why is any further
conversion considered as I have an exact matching function amin?
2) It's the templated constructor of DenseVector causing the trouble.
I cannot make it explicit, what would work in the example. Is there
another way to have this constructor, but prevent it from being
considered a candidate, if Impl is DenseVector<T2>?
best regards,
Alex
I have already posted and discussed the following problems once, but
despite really helpful hints I did not get any further with my problem
(I at least learned, first to exactly consider why something does not
work instead of immediately searching for work arounds) . I have the
following code resulting in an ambiguity:
--------------------------------------------------------
template <typename Impl>
class Vector {};
template <typename Ref>
class VectorView : public Vector<VectorView<Ref> >
{
public:
operator const Ref &() const { return _ref; }
private:
Ref _ref;
};
template <typename T>
class DenseVector : public Vector<DenseVector<T> >
{
public:
DenseVector() {}
template <typename Impl>
DenseVector(const Vector<Impl> &rhs) {}
};VectorView said:(); }
int amin(const DenseVector<double> &x) { return 1; }
int amin(const DenseVector<float> &x) { return -1; }
int main()
{
DenseVector<double> x;
int i = amin(x(1,3));
}
--------------------------------------------------------
Some things are not really clear to me:
1) what causes the ambiguity. The conversion operator in
class VectorView returns a DenseVector<double>. Why is any further
conversion considered as I have an exact matching function amin?
2) It's the templated constructor of DenseVector causing the trouble.
I cannot make it explicit, what would work in the example. Is there
another way to have this constructor, but prevent it from being
considered a candidate, if Impl is DenseVector<T2>?
best regards,
Alex