在Windows上使用cygwin64,该程序将无法编译:
program test
implicit none
!define my type
type myType
real::foo
integer::bar
end type myType
!define an operator for this type
interface operator (>)
logical function compare(a,b)
type(myType),intent(in) :: a,b
compare = a%foo>b%foo
end function compare
end interface operator (>)
!simple example of operator usage
type(myType) :: tfoo, tbar
tfoo = card(1.,2); tbar = card(3.,4)
print*, tfoo>tbar
end program test
Run Code Online (Sandbox Code Playgroud)
gfortran (只有参数是"std = f2008")告诉我:
type(myType),intent(in) :: a,b
1
Error: Derived type ‘mytype’ at (1) is being used before it is …Run Code Online (Sandbox Code Playgroud) 给定一个不可复制/可移动的 struct U,该结构的成员不能在构造函数中分配(请参阅C)。它们只能通过成员初始值设定项列表来初始化(请参阅 参考资料S)。
struct U {
U(int x);
U(U &other) = delete;
U(U &&other) = delete;
};
struct S {
S(int x) : u(x) {}
U u;
};
struct C {
C(int x) { u = U(x); } // compiler complains: cannot assign
U u;
};
Run Code Online (Sandbox Code Playgroud)
错误:
<source>:13:5: error: constructor for 'C' must explicitly initialize the member 'u' which does not have a default constructor
C(int x) { u = U(x); }
^
<source>:14:7: …Run Code Online (Sandbox Code Playgroud)