Joachim
Joachim

Reputation: 3260

Conjoin vectors of shared_ptr

i use smart pointers in the following way:

typedef std::tr1::shared_ptr<RealAlgebraicNumber> RealAlgebraicNumberPtr;

I'm using the smart pointer things because RealAlgebraicNumber is an "abstract" superclass. It works fine and now i want a class to encapsulate a vector. It looks like this:

class RealAlgebraicPoint
{
public:
    RealAlgebraicPoint (vector<RealAlgebraicNumberPtr>& v);
    RealAlgebraicPoint (RealAlgebraicPoint& R);
    RealAlgebraicPoint conjoin (const RealAlgebraicNumber& N);
private:
    vector<RealAlgebraicNumberPtr> mNumbers;
    unsigned int mSize;
};

And the implementation is like this:

RealAlgebraicPoint::RealAlgebraicPoint(vector<RealAlgebraicNumberPtr>& v)
    : mNumbers(v), mSize(mNumbers.size()) {}
RealAlgebraicPoint::RealAlgebraicPoint(RealAlgebraicPoint& R)
    : mNumbers(R.mNumbers), mSize(mNumbers.size()) {}
RealAlgebraicPoint RealAlgebraicPoint::conjoin (const RealAlgebraicNumber& N)
{
    vector<RealAlgebraicNumberPtr> v;
    // do something fancy with v!
    return RealAlgebraicPoint(v); // this is line 58
}

Unfortunatly I get ugly errors like this:

RealAlgebraicPoint.cpp: In member function 'GiNaC::RealAlgebraicPoint GiNaC::RealAlgebraicPoint::conjoin(const GiNaC::RealAlgebraicNumber&)':
RealAlgebraicPoint.cpp:58:32: error: no matching function for call to 'GiNaC::RealAlgebraicPoint::RealAlgebraicPoint(GiNaC::RealAlgebraicPoint)'
RealAlgebraicPoint.cpp:46:1: note: candidates are: GiNaC::RealAlgebraicPoint::RealAlgebraicPoint(GiNaC::RealAlgebraicPoint&)
RealAlgebraicPoint.cpp:42:1: note: GiNaC::RealAlgebraicPoint::RealAlgebraicPoint(std::vector<std::tr1::shared_ptr<GiNaC::RealAlgebraicNumber> >&)
RealAlgebraicPoint.cpp:38:1: note: GiNaC::RealAlgebraicPoint::RealAlgebraicPoint(unsigned int&)

Any ideas? I'm really consfused why he trys to call RealAlgebraicPoint(GiNaC::RealAlgebraicPoint) as I am only calling RealAlgebraicPoint(std::vector<std::tr1::shared_ptr<GiNaC::RealAlgebraicNumber> >&).

Thank you!

Joachim

Upvotes: 1

Views: 119

Answers (1)

James Kanze
James Kanze

Reputation: 153977

The copy constructor should take a reference to const.

Upvotes: 3

Related Questions