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 3228026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:38:37+00:00 2026-05-17T16:38:37+00:00

I want to use a stack to store indices of an array,so I use

  • 0

I want to use a stack to store indices of an array,so I use the following typedef,where istack is a template class for stack:

typedef istack<size_t> IndexStack;

and I declare a stack by

IndexStack    stack;

But when I call the following function (where A.size() returns a size_t);

stack.push_back(A.size());

GCC gives the following error

sort.cpp: In function 'void quicksort2(Array&)':
sort.cpp:50:27: error: no matching function for call to 'istack<unsigned int>::push_back(size_t)'
iarray.h:103:8: note: candidate is: void istack<T>::push_back(T&) [with T = unsigned int]

How can I make it work?

  • 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-05-17T16:38:38+00:00Added an answer on May 17, 2026 at 4:38 pm
    #include <cstddef>
    template <class T>
    struct istack
    {
        void push_back(T& value);
        std::size_t size() const;
    };
    
    int main()
    {
        typedef istack<size_t> IndexStack;
        IndexStack    a, stack;
        stack.push_back(a.size());
    }
    

    This code produces an error

    In function 'int main()':
    13 no matching function for call to 'istack<unsigned int>::push_back(size_t)'
    note 5 candidates are: void istack<T>::push_back(T&) [with T = unsigned int]
    

    Note that it lists candidates. (I suspect you are not reading / posting the entire error message.)

    The given candidate doesn’t match the call, because the reference is non-const. A temporary (such as the result of a.size()) cannot be bound to a non-const reference.

    push_back should be taking a const T& value

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use jQuery with a GridView which contains textboxes, but I'm stuck
I want to use the Web Browser control within an mono application, but when
I want to use CodeDOM to both declare and initialize my static field in
I am building a DLL that another application would use. I want to store
I want to use Markdown for my website's commenting system but I have stumbled
I want to use pdo in my application, but before that I want to
I want to store code similar to how jsfiddle stores code. I currently use
Below is my stored procedure. I want use stored procedure select all row of
I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom
I want to use Powershell to write some utilities, leveraging our own .NET components

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.