[Trilinos-Users] Teuchos:: RCP function arguments, reference, derived types

Nico Schlömer nico.schloemer at UA.AC.BE
Wed Jan 20 07:15:45 MST 2010


I've encountered a strange behavior of Teuchos::RCP and I'm not sure if
it's a bug, a feature, or just stanard C++ behavior. Consider the
following setup:

============= *snip* =============
void myFun( Teuchos::RCP<BaseType> & x ){

Teuchos::RCP<DerivedType> xx = Teuchos::rcp( new [...] )

f(xx); // Error!
============= *snap* =============

Compiling this, g++ will complain about

============= *snip* =============
error: invalid initialization of reference of type
‘Teuchos::RCP<BaseType>&’ from expression of type
============= *snap* =============

It *does work, though, when not defining the function argument as
reference, that, is wiping the "&" above; it works as well when not
passing RCP, but the objects themselves by reference.

A minimal example with Tpetra::{Multi}Vector's is attached.

What's the explanation for this?

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bugtest.cpp
Url: https://software.sandia.gov/pipermail/trilinos-users/attachments/20100120/0947f6ad/attachment.pl 

More information about the Trilinos-Users mailing list