[omniORB] compiling template with I::_ptr_type *

Janet Tvedt tvedt@noao.edu
Fri, 2 Feb 2001 10:47:36 -0700 (MST)


Sorry, I had mentioned Solaris 2.8 and gcc version 2.95.2 in a previous
message.  I was hoping my mistake would be obvious to someone else
just by looking at the calls.  In the process of paring down my 
code to a more simple example, I discovered the problem (actually
two).  1) My template function actually calls another template function
where I had not included <Type> in the call.  2) Within the second
template function I declared an intermediate variable "Type *" instead
of "typename Type::_ptr_type".

The following works (with lots of details omitted):


Echo_ptr echoRef;
CORBA::Object_var temp = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::_narrow(temp);
getObjectReference <Echo>( &echoRef, "Echo 3", rootContext, 3);


template <class Type> 
int
getObjectReference(Type **a, const char *name, CosNaming::NamingContext_var nc, int maxRetries)
{ 
   ...

   getCosNamingObjectRef<Type>(a, cosName, nc);
   ...
 }

template <class Type> 
int
getCosNamingObjectRef(typename Type::_ptr_type *a, CosNaming::Name cosName, 
	              CosNaming::NamingContext_var nc)
{
     ...
     
     typename Type::_ptr_type ref
     ...
  
     *a = ref;
     ...
}

Thanks for the suggestions!


--------------------------------------------------------------------------
Janet Tvedt, National Solar Observatory/SOLIS   Internet: tvedt@noao.edu
P.O. Box 26732, Tucson, AZ  85732-6732          Phone:    (520) 318-8388
950 N. Cherry Ave., Tucson, AZ  85719           FAX:      (520) 318-8278


> You do not mention the compiler version you are using, you
> do not include the exact messages output from the compiler, and
> you do not provide a fully compilable test-case to reproduce
> your error.   This makes it difficult for other people to help you.
> 
> > 
> > template <class Type> 
> > int
> > getObjectReference(Type **a, const char *name, CosNaming::NamingContext_var nc, int maxRetries)
> > { ... }
> 
> 
> > 
> > The call to the function looked like the following (for an interface OCS::IAttributeDB)
> > 
> > OCS::IAttributeDB *obj;
> > getObjectReference( &obj, ... );
> 
> How about:
> 
> template <class Type>
> int
> getObjectReference( typename Type::_ptr_type a, const char *name, 
>                     CosNaming::NamingContext_ptr nc, int maxRetries);
> 
> then to call it:
> 
> OCS::IAttributeDB_ptr obj;
> 
> getObjectReference<OCS::IAttributeDB>(obj, name, nc, maxRetries);
> 
> -- 
> Craig Rodrigues        
> http://www.gis.net/~craigr    
> rodrigc@mediaone.net          
>