【发布时间】:2013-02-05 08:30:42
【问题描述】:
我有一个模板化的 SortedLinkedList 类,它按主题 A 对象的字符串字段中包含的值对其进行排序。
这里是主题 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;
};
我想在列表中找到存储其字符串字段中带有"tulgey" 的TopicA 对象的位置,所以我调用AList.getPosition( "tulgey" ); 这是getPosition() 标头:
template <class ItemType>
int SortedLinkedList<ItemType>::getPosition( const ItemType& anEntry ) const
但是当我尝试调用 getPosition() 时,编译器在标题中给出了错误。为什么?难道我没有从string 到TopicA 的转换构造函数吗?
如果有什么不同,这里是TopicA( const string & arg )的定义:
TopicA::TopicA( const string & arg ) : sValue( arg ), dValue( 0 ), iValue( 0 )
{
}
【问题讨论】:
标签: c++ templates constructor