Skip to content

[Rcpp-devel] Using namespaces to improve code readability

2 messages · Savitsky, Terrance, Douglas Bates

#
I note that employing the namespace declaration -  using namespace arma;
- allows one to use the declaration of a new armadillo matrix under an
RcppArmadillo header with - mat X(Xr.begin() .... - instead of -
arma::mat X(Xr.begin() ...

 

Do you not recommend this approach due to possibility for overlapping
class names between Rcpp and armadillo?

 

Thanks, Terrance Savitsky

 


__________________________________________________________________________

This email message is for the sole use of the intended recipient(s) and
may contain confidential information. Any unauthorized review, use,
disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101216/79907d9a/attachment.htm>
#
On Thu, Dec 16, 2010 at 5:18 PM, Savitsky, Terrance <savitsky at rand.org> wrote:
If there are name clashes it is always possible to use fully qualified
names to disambiguate the choice.  That is, arma::mat can be used even
after a

using namespace arma;

declaration.  However I don't think there are name clashes between
Armadillo and Rcpp at present.

One recommendation that many C++ programmers miss is that when you
separate the declarations of classes, etc. from the definition, by
writing both a foo.h and a foo.cpp file, it is not a good idea to have
a using namespace declaration in the header file, foo.h, because of
downstream consequences.  If another programmer includes your header
file to get the declarations of your classes etc. then their name
resolution will be changed by your using namespace directive, which is
not a good idea.  The using namespace declaration should be used in
the .cpp file only.