compilation error in class template



 DEVELOP > c-Plus-Plus > compilation error in class template

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "mthread"
Date: 28 Jan 2008 04:50:17 AM
Object: compilation error in class template
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;
}
.

User: "tragomaskhalos"

Title: Re: compilation error in class template 28 Jan 2008 05:35:35 AM
On Jan 28, 10:50=A0am, mthread <rjk...@gmail.com> wrote:

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

typename list<Type>::iterator pos;

=A0 =A0 =A0 =A0 return 1;

}

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

Title: Re: compilation error in class template 28 Jan 2008 08:34:01 AM
On Jan 28, 4:35 pm, tragomaskhalos <dave.du.verg...@logicacmg.com>
wrote:

On Jan 28, 10:50 am, mthread <rjk...@gmail.com> wrote:

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


typename list<Type>::iterator pos;

return 1;


}


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

Hi,
thanx.
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER