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

  • Home
  • SEARCH
  • 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 8677035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:21:02+00:00 2026-06-12T20:21:02+00:00

It seems like the compiler is very close to doing what I want (because

  • 0

It seems like the compiler is very close to doing what I want (because it calls out my function as a candidate), but I have no idea what I’m doing wrong.

#include <stdio.h>
#include <stdlib.h>
#include <list>

using namespace std;

template <class U, template<class U> class T>
void AppendSorted( T<U>& l, U val )
{
  typename T<U>::reverse_iterator rt = l.rbegin();

  while( ((*rt) > val) && (rt != l.rend()) )
    rt++;

  l.insert( rt.base(), val );
}

int main( int argc, char* argv[] )
{
    list<int> foo;
    AppendSorted<int, list<int> >( foo, 5 );

    list<int>::iterator i;
    for( i = foo.begin(); i != foo.end(); i++ )
    {
        printf("%d\n",*i);
    }

    return 0;
}

The error I’m getting is:

test.cpp: In function ‘int main(int, char**)’:
test.cpp:21:43: error: no matching function for call to ‘AppendSorted(std::list<int>&, int)’
test.cpp:21:43: note: candidate is:
test.cpp:8:6: note: template<class U, template<class U> class T> void AppendSorted(T<U>&, U)
  • 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-12T20:21:04+00:00Added an answer on June 12, 2026 at 8:21 pm

    This signature

    template <class U, template<class U> class T>
    void AppendSorted( T<U>& l, U val )
    

    indicates that there will be one concrete type (class U) and one template (template<class U> class T).

    This invocation

    AppendSorted<int, list<int> >( foo, 5 );
    

    provides two concrete types, int and list<int>. list is a template, list<int> is a concrete type, a template instance, but not a template.

    Just change the function to accept the concrete type of the collection:

    template <class U, class T>
    void AppendSorted( T& l, U val )
    {
      typename T::reverse_iterator /* or auto */ rt = l.rbegin();
    
      while( (rt != l.rend()) && ((*rt) > val) )
        rt++;
    
      l.insert( rt.base(), val );
    }
    

    And let the compiler infer the type arguments, instead of specifying them.

    AppendSorted( foo, 5 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Nant seems very compiler-centric - which is guess is because it's considered a .NET
Seems like i need some help with a project. I have a routine ,
Seems like this should be obvious, but how do I send arrow key presses
Seems like this should be simple, but powershell is winning another battle with me.
It seems that in most cases the C# compiler could call Dispose() automatically. Like
I understand that this may seems a very basic question, but I always thought
Why won't the following C code compile? It seems like it should just change
Seems like there should be... Right now it just seems like magic that you
Seems like cuke doesn't show the full error message (at least when problem occurs
Seems like a standard approach for an ioc when given a scenario like (C#

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.