Topic A オブジェクトを文字列フィールドに含まれる値でソートする、テンプレート化された SortedLinkedList クラスがあります。
トピック 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 )
{
}