我打算实现我的"稀疏矢量"和"矢量"类的乘法运算符.以下简化的代码演示显示了我的问题
Vector.hpp中的Vector类
#pragma once
template <typename T>
class Vector
{
public:
Vector() {}
template <typename Scalar>
friend Vector operator*(const Scalar &a, const Vector &rhs) // #1
{
return Vector();
}
};
Run Code Online (Sandbox Code Playgroud)
SpVec.hpp中的Sparse Vector类
#pragma once
#include "Vector.hpp"
template <typename T>
class SpVec
{
public:
SpVec() {}
template <typename U>
inline friend double operator*(const SpVec &spv, const Vector<U> &v) // #2
{
return 0.0;
}
};
Run Code Online (Sandbox Code Playgroud)
main.cpp中的测试代码:
#include "Vector.hpp"
#include "SpVec.hpp"
#include …Run Code Online (Sandbox Code Playgroud) 我想在我的Fortran代码中为派生类型实现用户定义的I/O过程.但是,write这些过程中的语句不能在两个连续write语句之间产生新行.派生类型和过程定义如下.
模块:
module station_module
implicit none
character(8), parameter :: FmtFloat = '(5E15.7)'
type :: station
integer, private :: ns = 0
real, public, allocatable :: xloc(:), yloc(:), zloc(:)
contains
procedure, public :: import_station
procedure, public :: export_station
procedure, private :: read_station
generic, public :: read (formatted) => read_station
procedure, private :: write_station
generic, public :: write (formatted) => write_station
final :: destruct_station
end type station
interface station
module procedure new_station
end interface station
contains
function new_station(n) …Run Code Online (Sandbox Code Playgroud)