Sign in to follow this  

how do I use pointer classes in parameters?

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this