A forward declaration used by template class issue on gcc 4.4.1

Ian Lance Taylor iant@google.com
Sat Oct 24 03:18:00 GMT 2009


"Zhang Lin" <zhanglin0714@163.com> writes:

> class ACE_Message_Queue_NT;

> template <class T>
> ACE_Message_Queue_NT *ACE_Message_Queue_Factory<T>::create_NT_message_queue (int max_threads)
> {
>  ACE_Message_Queue_NT *tmp = 0;
>
>  tmp = new ACE_Message_Queue_NT (max_threads);
>
>  return tmp;
> }
>
> class ACE_Message_Queue_NT
> {
> public:
>  ACE_Message_Queue_NT (int)
>  {
>  }
> };

> This code can be accepted by Microsoft VC 7.1, but GCC reported the following error:
> main.cpp: In static member function 'static ACE_Message_Queue_NT* ACE_Message_Queue_Factory<T>::create_NT_message_queue(int)':
> main.cpp:15: error: invalid use of incomplete type 'struct ACE_Message_Queue_NT'
> main.cpp:1: error: forward declaration of 'struct ACE_Message_Queue_NT'
>
> Is there any description about the error above in C++ standard?

This question is not appropriate for the mailing list gcc@gcc.gnu.org.
It would be appropriate for gcc-help@gcc.gnu.org.  Please take any
followups to gcc-help.  Thanks.


C++ templates are not macros.  Non-dependent names are looked up at
the point of the template definition.  They are not looked up at the
point of template use.  The C++ standard specifies that so that
templates behave consistently rather than changing behaviour depending
upon when they are instantiated.  For more information, look for
descriptions of two-phase lookup.  I don't use the Microsoft compiler,
but I've heard reports that it does not implement two-phase lookup
correctly.

Ian



More information about the Gcc mailing list