Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 共享ptr的连接向量_C++_Tr1 - Fatal编程技术网

C++ 共享ptr的连接向量

C++ 共享ptr的连接向量,c++,tr1,C++,Tr1,我以以下方式使用智能指针: typedef std::tr1::shared_ptr<RealAlgebraicNumber> RealAlgebraicNumberPtr; typedef std::tr1::shared_ptr realagebraicnumberpt; 我使用智能指针是因为RealAlgebraicNumber是一个“抽象”超类。它工作得很好,现在我想要一个类来封装一个向量。看起来是这样的: class RealAlgebraicPoint { publi

我以以下方式使用智能指针:

typedef std::tr1::shared_ptr<RealAlgebraicNumber> RealAlgebraicNumberPtr;
typedef std::tr1::shared_ptr realagebraicnumberpt;
我使用智能指针是因为RealAlgebraicNumber是一个“抽象”超类。它工作得很好,现在我想要一个类来封装一个向量。看起来是这样的:

class RealAlgebraicPoint
{
public:
    RealAlgebraicPoint (vector<RealAlgebraicNumberPtr>& v);
    RealAlgebraicPoint (RealAlgebraicPoint& R);
    RealAlgebraicPoint conjoin (const RealAlgebraicNumber& N);
private:
    vector<RealAlgebraicNumberPtr> mNumbers;
    unsigned int mSize;
};
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
}
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&)
class RealAlgebraicPoint
{
公众:
实代数点(向量&v);
RealAlgebraicPoint(RealAlgebraicPoint&R);
实代数点连接(常数实代数数&N);
私人:
向量数;
无符号整数mSize;
};
具体实施如下:

class RealAlgebraicPoint
{
public:
    RealAlgebraicPoint (vector<RealAlgebraicNumberPtr>& v);
    RealAlgebraicPoint (RealAlgebraicPoint& R);
    RealAlgebraicPoint conjoin (const RealAlgebraicNumber& N);
private:
    vector<RealAlgebraicNumberPtr> mNumbers;
    unsigned int mSize;
};
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
}
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&)
realagebraicpoint::realagebraicpoint(向量&v)
:mNumbers(v),mSize(mNumbers.size()){
RealAlgebraicPoint::RealAlgebraicPoint(RealAlgebraicPoint&R)
:mNumbers(R.mNumbers),mSize(mNumbers.size()){}
realagebraicpoint realagebraicpoint::conjoin(const realagebraicnumber&N)
{
向量v;
//用v做些有趣的事!
返回RealAlgebraicPoint(v);//这是第58行
}
不幸的是,我犯了这样的错误:

class RealAlgebraicPoint
{
public:
    RealAlgebraicPoint (vector<RealAlgebraicNumberPtr>& v);
    RealAlgebraicPoint (RealAlgebraicPoint& R);
    RealAlgebraicPoint conjoin (const RealAlgebraicNumber& N);
private:
    vector<RealAlgebraicNumberPtr> mNumbers;
    unsigned int mSize;
};
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
}
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&)
realagebraicpoint.cpp:在成员函数“GiNaC::realagebraicpoint GiNaC::realagebraicpoint::conjoin(const GiNaC::realagebraicnumber&)”中:
RealAlgebraicPoint.cpp:58:32:错误:调用“GiNaC::RealAlgebraicPoint::RealAlgebraicPoint(GiNaC::RealAlgebraicPoint)”时没有匹配的函数
cpp:46:1:注:候选对象是:GiNaC::RealAlgebraicPoint::RealAlgebraicPoint(GiNaC::RealAlgebraicPoint&)
cpp:42:1:注:GiNaC::RealAlgebraicPoint::RealAlgebraicPoint(std::vector&)
realagebraicpoint.cpp:38:1:注意:GiNaC::realagebraicpoint::realagebraicpoint(unsigned int&)
有什么想法吗?我真的很理解为什么他试图调用
realagebraicpoint(GiNaC::realagebraicpoint)
,因为我只调用
realagebraicpoint(std::vector&)

谢谢大家!


Joachim

复制构造函数应该引用const。

这对我来说很好。发布你的include和using语句。应该这样做,但这无关紧要。不是答案。@AndreasHaferburg:这是相关的。函数试图返回一个临时函数的副本,这只有在副本构造函数引用const时才可能发生。@AndreasHaferburg这是相关的,因为编译器错误消息抱怨无法调用副本构造函数。由于复制构造函数是公共的,所以它不能调用它的唯一(或至少最可能)原因是因为复制构造函数采用非常量引用(因此不能使用临时构造函数调用)。