[Rcpp-devel] Creating a std::vector of objects with const members

Darren Cook darren at dcook.org
Fri Oct 7 01:23:49 CEST 2011


> It is not a big deal in this case but I am wondering how to define the
> population protocol using something like std::vector so that
> elementary protocols can be added or removed but each elementary
> protocol is read-only.
> ... like declaring the vector as std::vector<const ElemProt> but
> that doesn't seem to work in the push_back method for the vector.

That should work (or I've misunderstood the problem).
"std::vector<const ElemProt>" means pass-by-value. Could that have
caused trouble? (E.g. if you didn't have a copy constructor defined.)

If so, std::vector<const ElemProt*> might work? (Or better is vector of
smart pointers, so you don't have to worry about memory management.)
Or, define a copy constructor.

Darren



-- 
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)


More information about the Rcpp-devel mailing list