• Advertisement
Sign in to follow this  

how do I use pointer classes in parameters?

This topic is 3786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I want something like... void function (someclass &somepointer) ???

Share this post


Link to post
Share on other sites
Advertisement
The term 'pointer class' is not something used very often.

If you're talking about a smart pointer class, such as std::auto_ptr or boost::shared_ptr, then their argument-passing semantics depend on which you use. All of them support pass-by-value, and some support passing by constant reference:

void function(std::auto_ptr<int> ptr);
void function(boost::shared_ptr<int> ptr);
void function(const boost::shared_ptr<int> & ptr);


If you're talking about passing a 'class pointer', you pass it like any other type (because a pointer to a class is a type like any other). For instance:
void function(std::string *ptr); // By value
void function(std::string *&ptr); // By reference

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement