Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:54:23+00:00 2026-06-18T08:54:23+00:00

I have a templated SortedLinkedList class that sorts Topic A objects by the value

  • 0

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 )
{
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:54:24+00:00Added an answer on June 18, 2026 at 8:54 am

    You are probably invoking two implicit conversions, from const char[7] to std::string, and from std::string to TopicA. But you are only allowed one implicit conversion. You can fix the problem by being more explicit:

    AList.getPosition( std::string("tulgey") ); // 1 conversion
    AList.getPosition( TopicA("tulgey") );      // 1 conversion
    

    Alternatively, you can give TopicA a constructor taking a const char*:

    TopicA( const char * arg ) : sValue( arg ), dValue( 0 ), iValue( 0 ) {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a templated class that I want to avoid copying (because of the
I have a templated class for volume objects where operator+= is implemented as a
I have a templated container class that looks something like this: template <class ItemType>
I have a templated function that invokes another function and stores its return value,
I have several templated objects that all implement the same interface: I.E. MyObject<datatype1> obj1;
I have a templated class holding a value. Is it possible to add a
I have a templated class that is dependent on two template parameters to calculate
lets say i have a templated class template <typename T> struct Widget { //generalized
I have a templated class, that can have a map type as template parameter.
Say I have a templated Action template <class ArgT> struct Action { Action(::boost::function< void(ArgT)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.