compilation error in class template

M

mthread

Hi,
I get the compilation error,
main.cpp : In member function 'int
SingleQueue<Type>::Show_qelements()':
main.cpp:25: error: expected `;' before 'pos'
when I compile the code given below. Kinldy let me know what is
the change I need to do.

#include <iostream>
#include <list>
using namespace std;

template <class Type>
class SingleQueue
{
private :
pthread_mutex_t a_mutex;
pthread_cond_t a_cond;
char a_isAvlbl;
list<Type> a_ll;
public :
int Show_qelements();
};

template <class Type>
int SingleQueue<Type>::Show_qelements()
{
list<Type>::iterator pos; //Compilation error occurs here
return 1;
}

struct Message
{
int no;
};

int main()
{
SingleQueue<Message*> queue;

queue.Show_qelements();

return 1;
}
 
T

tragomaskhalos

template <class Type>
int SingleQueue<Type>::Show_qelements()
{
        list<Type>::iterator pos; //Compilation error occurs here

typename list said:
        return 1;

}

Again with the typename ...
The compiler doesn't know what iterator is, it could be anything,
so you have to help it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top