我想要拷贝一份现有的NumericVector<Number>
下面一段是NumericVector的构造函数:
/**
* This _looks_ like a copy assignment operator, but note that,
* unlike normal copy assignment operators, it is pure virtual. This
* function should be overridden in derived classes so that they can
* be copied correctly via references to the base class. This design
* usually isn't a good idea in general, but in this context it
* works because we usually don't have a mix of different kinds of
* NumericVectors active in the library at a single time.
*
* \returns A reference to *this as the base type.
*/
virtual NumericVector<T> & operator= (const NumericVector<T> & v) = 0;
/**
* The 5 special functions can be defaulted for this class, as it
* does not manage any memory itself.
*/
NumericVector (NumericVector &&) = default;
NumericVector (const NumericVector &) = default;
NumericVector & operator= (NumericVector &&) = default;
我用的另一个函数:
/**
* Get a raw NumericVector with the given name.
*/
NumericVector<Number> &
SystemBase::getVector(const std::string & name)
{
return system().get_vector(name);
}
然后我打的代码是:
NumericVector<Number> old_d = _nl.getVector("d");
我是想把_nl.getVector("d")
拷贝出来放到old_d里面,但是报错了:
/home/user01/projects/moose/framework/src/executioners/Transient.C:471:54: error: cannot allocate an object of abstract type 'libMesh::NumericVector<double>'
471 | NumericVector<Number> old_d = _nl.getVector("d");
我看了下是因为我构造函数用的不对。
我有几个不懂:
1、=default 是不是代表 相当于我们常用的构造函数的语法,而不是什么都不做的一个空函数?
2、NumericVector && 是什么意思?
3、为什么构造函数可以用NumericVector &&和NumericVector &作为参数,不应该是NumericVector && a和NumericVector & a 之类的吗?
4、应该怎么拷贝?我试过
NumericVector<Number> old_d(_nl.getVector("d"));
但是也报错了