Hi, You should avoid pointers unless you are forced to use them, eg by another api you dont control.
C++ has references and these are much safer and nicer to use. Pointers are dangerous. Also, when you write functions that modify a reference (or a pointer) you can always ask yourself if this could/should be a member function of the class rather than a free function. Romain Le 1 sept. 2010 à 09:46, Christian Gunning <[email protected]> a écrit : > Is there a good rule of thumb for when to write a function that > returns an object (to be assigned to a variable) versus passing the > object pointer to the function to be modified in place? > > I'm more familiar with R's function programming style, which i've seen > in Rcpp documents and list examples: > > //1 > b = fx(a); > > whereas traditional C forbids returning vectors and enforces modify-in-place: > > //2 > fx(a, &b); > > Is there compiler magic that makes these two cases equivalent, or > should 2 to be preferred for heavy lifting? > > thanks, > Christian Gunning > University of New Mexico > _______________________________________________ > Rcpp-devel mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel _______________________________________________ Rcpp-devel mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
