[Trilinos-Users] Teuchos::RCP Call by reference

Bartlett, Roscoe A. bartlettra at ornl.gov
Mon Aug 12 07:44:47 MDT 2013


FYI:

There is a lot of tutorial material on the behavior of these C++ tools and interaction with the C++ type system including inheritance, etc. in the document:

    http://web.ornl.gov/~8vt/TeuchosMemoryManagementSAND.pdf

There is a lot of material there but it should answer almost any question one might have about the usage of these smart pointer classes.

-Ross

P.S. No one ever said that C++ was easy; not even the inventor of C++ would claim that I don't think.


> -----Original Message-----
> From: trilinos-users-bounces at software.sandia.gov [mailto:trilinos-users-
> bounces at software.sandia.gov] On Behalf Of Ramsey, James J CIV (US)
> Sent: Friday, August 09, 2013 8:52 AM
> To: trilinos-users at software.sandia.gov
> Subject: Re: [Trilinos-Users] Teuchos::RCP Call by reference
> 
> ________________________________________
> From: trilinos-users-bounces at software.sandia.gov [trilinos-users-
> bounces at software.sandia.gov] on behalf of Sunghwan Choi
> [sunghwanchoi91 at gmail.com]
> Sent: Friday, August 09, 2013 2:49 AM
> To: trilinos-users at software.sandia.gov
> Subject: Re: [Trilinos-Users] Teuchos::RCP Call by reference
> 
> Dear all,
> I am just confused;;;   I have simple question on Teuchos::RCP
> 
> Teuchos::RCP<Epetra_Vector>
> Teuchos::RCP<Epetra_MultiVector> a
> a=b
> 
> Can I put b on a without any conversion?
> ________________________________________
> 
> Even without knowing much about the Teuchos::RCP template myself, I'm
> pretty sure that the answer is no.
> 
> Teuchos::RCP<Epetra_Vector> and Teuchos::RCP<Epetra_MultiVector> are,
> as far the C++ compiler is concerned, completely different classes.
> Remember, that even though Epetra_Vector inherits from
> Epetra_MultiVector, Teuchos::RCP<Epetra_Vector> does *not* inherit from
> Teuchos::RCP<Epetra_MultiVector>. (Even if one of the RCPs *did* inherit
> from the other, that wouldn't help you. See here:
> http://stackoverflow.com/questions/9161512/assignment-operator-
> inheritance )
> 
> If I look at the header file Teuchos_RCP.hpp, I see two signatures for the
> assignment operator:
> 
> RCP<T>& RCP<T>::operator=(const RCP<T>& r_ptr)
> RCP<T>& RCP<T>::operator=(ENull)
> 
> The second one isn't relevant to what you want to do, and the first one
> requires that both sides of the assignment operator be of the same class.
> 
> I would recommend using the copy constructor for a MultiVector, that is,
> 
> Teuchos::RCP<Epetra_Vector> b;
> // Do stuff to fill in the contents of what is pointed to by "b" ...
> Teuchos::RCP<Epetra_MultiVector> a(new Epetra_MultiVector(*b))
> 
> at least if you want "a" to be essentially a copy of "b". For the other way
> round, I suggest looking at the constructor of Epetra_Vector that accepts a
> MultiVector, in the Epetra documentation:
> http://trilinos.sandia.gov/packages/docs/r11.4/packages/epetra/doc/html/cl
> assEpetra__Vector.html
> 
> 
> _______________________________________________
> Trilinos-Users mailing list
> Trilinos-Users at software.sandia.gov
> http://software.sandia.gov/mailman/listinfo/trilinos-users




More information about the Trilinos-Users mailing list