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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:25:00+00:00 2026-05-26T18:25:00+00:00

I don’t know how to get to use more than one client function in

  • 0

I don’t know how to get to use more than one client function in a program with template I can do one function and have it work but when it comes to more than one and i attempt to use two or more , it gives me errors like this:

|17|error: 'T' was not declared in this scope|
|17|error: template argument 1 is invalid|
|17|error: template argument 2 is invalid|
|18|error: 'T' was not declared in this scope|
|18|error: template argument 1 is invalid|
|18|error: template argument 2 is invalid|
||In function 'int main()':|
|72|error: invalid initialization of reference of type 'int&' from expression of type 'std::queue<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::deque<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >'|
|17|error: in passing argument 1 of 'void print_queue(int&)'|
|73|error: invalid initialization of reference of type 'int&' from expression of type 'std::stack<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::deque<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >'|
|18|error: in passing argument 1 of 'void print_stack(int&)'|
|25|warning: unused variable 'pos'|
||=== Build finished: 10 errors, 1 warnings ===|

#include <iostream>

using namespace std;

#include <list>
#include <queue>
#include <stack>
template <typename T>        
void print_list(list<T> &);          // prototype for client function
void print_queue(queue<T> &);        // prototype for client function
void print_stack(stack<T> &);        // prototype for client function

int main()
{
    list< string > lst;
    queue< string > package, package_temp;
    stack< string > box, box_temp;
    string::size_type pos;
    string choice, str;
    bool choice_flag = true;

    do{
        cin >> choice;
        if(choice == "QUIT"){
            choice_flag = false;
            break;
        }
        else{
           lst.push_back(choice);
        }
    }while(choice_flag);

    print_list(lst);

    cout << endl;
    while(!lst.empty()){
        str = lst.front();
        if(str.find('P',0))
            box.push(str);
        else
            package.push(str);
            lst.pop_front();
        }

    print_queue(package);
    print_stack(box);

    return 0;
}

// client (not primitive) function to print each item on list lst
template <typename T>
void print_list(list<T> &lst)
{
    list<T> temp;
    T x;

    cout << "The elements on the list are: " << endl;
    while (!lst.empty()) {
        x = lst.front();
        lst.pop_front();
        cout << x << endl;
        temp.push_back(x);
    }

    while (!temp.empty()) {
        x = temp.front();
        temp.pop_front();
        lst.push_back(x);
    }

    return;
}

// client (not primitive) function to print each item on queue package
template <typename T>
void print_queue(queue<T1> &package)
{
    queue<T1> temp;
    T1 x;

    cout << "The elements on the list are: " << endl;
    while (!package.empty()) {
        x = package.front();
        package.pop();
        cout << x << endl;
        temp.push(x);
    }

    while (!temp.empty()) {
        x = temp.front();
        temp.pop();
        package.push(x);
    }

    return;
}
  • 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-26T18:25:01+00:00Added an answer on May 26, 2026 at 6:25 pm

    You have to have the template<...> above every template function you write. You forgot it above the print_queue function, so just add template<typename T> above it and that should solve it.

    You also haven’t #included the string header, which you need to do to use std::string.

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

Sidebar

Related Questions

Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know why but I can't find a solution to this. I have 3
Don't know the term for the red validation border, does it have one? I
Don't know what I did wrong. I have two indices with identical documents in
Don't know how to explain it better but i'm trying to get a response
Don't know a whole lot about streams. Why does the first version work using
Don't know if this has been answered before. Have custom routes to users. If
I don't have much PHP experience and I want to know how to best
Don't ask me why but i can't use this method because I need to
Don't know why I can't reply to people on here with only a small

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.