1

Can anyone help me with this errors. When i compile this simple program

#include<queue> 
using namespace std;
template<typename Queue>
int qtest(Queue & queue,typename Queue::Type item)
 {
    return 0;
 }

int main()
{
    std::queue<int> q;
    int t = qtest(q,3);
}

I get the errors like below

In function 'int main()':
error: no matching function for call to 'qtest(std::queue<int>&, int)'
note: candidate is:
note: template<class Queue> int qtest(Queue&, typename Queue::Type)
note:   template argument deduction/substitution failed:
 In substitution of 'template<class Queue> int qtest(Queue&, typename Queue::Type) [with 
Queue = std::queue<int>]':
   required from here
error: no type named 'Type' in 'class std::queue<int>'
warning: unused variable 't' [-Wunused-variable]
D-RAJ
  • 3,263
  • 2
  • 6
  • 24
Quy Trinh
  • 11
  • 1
  • error: no type named 'Type' in 'class std::queue' – PiotrNycz Feb 16 '21 at 15:50
  • Does this answer your question? [C++ Templates - Specifying a container type and that containers element type that it holds](https://stackoverflow.com/questions/3454373/c-templates-specifying-a-container-type-and-that-containers-element-type-tha) – user202729 Feb 16 '21 at 15:54

1 Answers1

3

std::queue doesn't have a member type called Type. That's what the compiler is telling us. I'm guessing what you're looking for is std::queue<int>::value_type.

template<typename Queue>
int qtest(Queue & queue,typename Queue::value_type item)
{
    return 0;
}

Reference: cppreference

D-RAJ
  • 3,263
  • 2
  • 6
  • 24