I have a templated SortedLinkedList class that sorts Topic A objects by the value contained in their string field.
Here’s Topic A:
struct TopicA
{
string sValue;
double dValue;
int iValue;
TopicA();
TopicA( const string & arg );
bool operator> ( const TopicA & rhs ) const;
bool operator< ( const TopicA & rhs ) const;
bool operator== ( const TopicA & rhs ) const;
bool operator!= ( const TopicA & rhs ) const;
};
I want to find the position in the list where a TopicA object with "tulgey" in its string field would be stored, so I call AList.getPosition( "tulgey" ); Here is the getPosition() header:
template <class ItemType>
int SortedLinkedList<ItemType>::getPosition( const ItemType& anEntry ) const
But when I try to call getPosition() the compiler gives me the error in the title. Why? Don’t I have a conversion constructor from string to TopicA?
If it makes any difference here’s the definition of TopicA( const string & arg ):
TopicA::TopicA( const string & arg ) : sValue( arg ), dValue( 0 ), iValue( 0 )
{
}
You are probably invoking two implicit conversions, from
const char[7]tostd::string, and fromstd::stringtoTopicA. But you are only allowed one implicit conversion. You can fix the problem by being more explicit:Alternatively, you can give
TopicAa constructor taking aconst char*: