本文整理汇总了C++中tr1::shared_ptr::add方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::add方法的具体用法?C++ shared_ptr::add怎么用?C++ shared_ptr::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tr1::shared_ptr
的用法示例。
在下文中一共展示了shared_ptr::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
tr1::shared_ptr<AbstractNumber> E::add(tr1::shared_ptr<AbstractNumber>number){
if (number -> getName() == "E")
{
if (number -> getSign() == '+' && getSign() == '+')
{
vector<tr1::shared_ptr<AbstractNumber> > M;
tr1::shared_ptr<AbstractNumber> two(new SmartInteger(2));
M.push_back(two);
M.push_back(shared_from_this());
tr1::shared_ptr<AbstractNumber> output(new MultExpression(M, '+'));
return output;
}
else if (number -> getSign() == '-' && getSign() == '-')
{
vector<tr1::shared_ptr<AbstractNumber> > N;
tr1::shared_ptr<AbstractNumber> twoN(new SmartInteger(-2));
N.push_back(twoN);
tr1::shared_ptr<AbstractNumber> me(new E());
N.push_back(me);
tr1::shared_ptr<AbstractNumber> output1(new MultExpression(N, '+'));
return output1;
}
else
{
tr1::shared_ptr<AbstractNumber> zero(new SmartInteger(0));
return zero;
}
}
else if(number->getName() == "MultExpression" || number->getName() == "SumExpression")
{
return number->add(shared_from_this());
}
vector<tr1::shared_ptr<AbstractNumber> > N;
N.push_back(number);
N.push_back(shared_from_this());
tr1::shared_ptr<AbstractNumber> output1(new SumExpression(N));
return output1;
}
示例2: if
// Adds number to this and returns the sum
//
// Parameters:
// shared_ptr<AbstractNumber> number number being added
//
// Returns:
// shared_ptr<AbstractNumber> resulting sum of addition
tr1::shared_ptr<AbstractNumber> Exponent::add(tr1::shared_ptr<AbstractNumber> number){
// Checks for cancellation
number = number->simplify();
if(abs(toDouble() - number->toDouble()) < 0.000001 &&
this->getSign() != number->getSign()){
tr1::shared_ptr<AbstractNumber> r(new SmartInteger(0));
return r;
}
// Checks for duplication/simplification
else if(abs(toDouble() - number->toDouble()) < 0.000001 &&
this->getSign() == number->getSign()){
vector< tr1::shared_ptr<AbstractNumber> > MultVector;
tr1::shared_ptr<AbstractNumber> i(new SmartInteger(2));
MultVector.push_back(i);
tr1::shared_ptr<AbstractNumber> me(new Exponent(base, power, sign));
MultVector.push_back(me);
tr1::shared_ptr<AbstractNumber> r(new MultExpression(MultVector, '+'));
return r;
}
//Can't tell if they add or not
else if(number->getName() == "SumExpression" ||
number->getName() == "MultExpression"){
return number->add(shared_from_this());
}
// Duplication necessary for simplification
// Assuming number is in simplest form
// No simplification possible
else{
vector< tr1::shared_ptr<AbstractNumber> > SumVector;
tr1::shared_ptr<AbstractNumber> me(new Exponent(base, power, sign));
SumVector.push_back(me);
SumVector.push_back(number);
tr1::shared_ptr<AbstractNumber> r(new SumExpression(SumVector));
return r;
}
}