小编Oba*_*bay的帖子

在接口块中"在定义之前使用派生类型"

在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)

cygwin fortran types gfortran operator-keyword

3
推荐指数
1
解决办法
1293
查看次数

初始化不可复制且不可移动类型的成员

给定一个不可复制/可移动的 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)

c++

0
推荐指数
1
解决办法
103
查看次数

标签 统计

c++ ×1

cygwin ×1

fortran ×1

gfortran ×1

operator-keyword ×1

types ×1