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

Ramsey, James J CIV (US) james.j.ramsey14.civ at mail.mil
Fri Aug 9 06:52:19 MDT 2013


________________________________________
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/classEpetra__Vector.html




More information about the Trilinos-Users mailing list