beginner question

C

Carter

Hi everyone,

This is another beginner question. I am having problems debugging some
code I am getting the error:

vertex.C: In member function ‘void vertex::set_chain_h(const
std::auto_ptr<boost::shared_ptr<chain> >&)’:
vertex.C:25: error: passing ‘const
std::auto_ptr<boost::shared_ptr<chain> >’ as ‘this’ argument of
‘std::auto_ptr<_Tp>::eek:perator std::auto_ptr_ref<_Tp1>() [w
ith _Tp1 = boost::shared_ptr<chain>, _Tp = boost::shared_ptr<chain>]’
discards qualifiers

which I do not quite understand in this case. Any help is appreciated.

Thanks in advance,

Carter.
(Code follows)

class XXX
{
public:
void set_chain_h( std::auto_ptr< boost::shared_ptr<chain> > const
& h)
{ _chain_h = h; }

private:
std::auto_ptr< boost::shared_ptr<chain> > _chain_h;

};
 
K

Kai-Uwe Bux

Carter said:
Hi everyone,

This is another beginner question. I am having problems debugging some
code I am getting the error:

vertex.C: In member function ?void vertex::set_chain_h(const
std::auto_ptr<boost::shared_ptr<chain> >&)?:
vertex.C:25: error: passing ?const
std::auto_ptr<boost::shared_ptr<chain> >? as ?this? argument of
?std::auto_ptr<_Tp>::eek:perator std::auto_ptr_ref<_Tp1>() [w
ith _Tp1 = boost::shared_ptr<chain>, _Tp = boost::shared_ptr<chain>]?
discards qualifiers

which I do not quite understand in this case. Any help is appreciated.

Thanks in advance,

Carter.
(Code follows)

class XXX
{
public:
void set_chain_h( std::auto_ptr< boost::shared_ptr<chain> > const
& h)

Note that h is passed as a const reference.
{ _chain_h = h; }

Assignment of auto_ptr objects is not const with respect to the RHS of the
assignment since ownership is transfered.

private:
std::auto_ptr< boost::shared_ptr<chain> > _chain_h;

};


Best

Kai-Uwe Bux
 
J

Jim Langston

Carter said:
Hi everyone,

This is another beginner question. I am having problems debugging some
code I am getting the error:

vertex.C: In member function ‘void vertex::set_chain_h(const
std::auto_ptr<boost::shared_ptr<chain> >&)’:
vertex.C:25: error: passing ‘const
std::auto_ptr<boost::shared_ptr<chain> >’ as ‘this’ argument of
‘std::auto_ptr<_Tp>::eek:perator std::auto_ptr_ref<_Tp1>() [w
ith _Tp1 = boost::shared_ptr<chain>, _Tp = boost::shared_ptr<chain>]’
discards qualifiers

which I do not quite understand in this case. Any help is appreciated.

Thanks in advance,

Carter.
(Code follows)

class XXX
{
public:
void set_chain_h( std::auto_ptr< boost::shared_ptr<chain> > const

The const means "I am not going to be changing any variables of this
instance.
& h)
{ _chain_h = h; }

And here you try to change a variable of the instant.
private:
std::auto_ptr< boost::shared_ptr<chain> > _chain_h;

};

Either remove the const, remove the assignment, or do something else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top