G
Glenn G. Chappell
I am trying to write two constructors for the same class. One takes an
iterator and so is a template. The other takes a particular type by
reference to const.
class Foo {
public:
template<typename InputIterator>
Foo(InputIterator i);
Foo(const Bar & b);
When I do this, trying to construct a Foo from a Bar calls the
template, not the constructor from a Bar. This is in VC++ 7.0. And it
does not matter which I declare first.
Questions: Is this a compiler oddity or standard behavior? Is there any
way around it?
I know a semi-solution. When I pass them both by value or both by
reference to const, it works.
template<typename InputIterator>
Foo(InputIterator i);
Foo(Bar b);
or
template<typename InputIterator>
Foo(const InputIterator & i);
Foo(const Bar & b);
But I would prefer not to do that. Any other ideas/thoughts?
iterator and so is a template. The other takes a particular type by
reference to const.
class Foo {
public:
template<typename InputIterator>
Foo(InputIterator i);
Foo(const Bar & b);
When I do this, trying to construct a Foo from a Bar calls the
template, not the constructor from a Bar. This is in VC++ 7.0. And it
does not matter which I declare first.
Questions: Is this a compiler oddity or standard behavior? Is there any
way around it?
I know a semi-solution. When I pass them both by value or both by
reference to const, it works.
template<typename InputIterator>
Foo(InputIterator i);
Foo(Bar b);
or
template<typename InputIterator>
Foo(const InputIterator & i);
Foo(const Bar & b);
But I would prefer not to do that. Any other ideas/thoughts?