Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C++;fortran 77中的类对象 有没有一种方法可以通过C++对象来使用FORTRAN 77?例如: C23456 program main write (*,*) 'Hello from FORTRAN 77!' call readstep('cube.stp'//CHAR(0),myshape) stop end 然后将MyStof用作C++对象,它将被保存在FORTRAN中使用的内存中,并将其传递给其他实际使用它的C++函数? 编辑:这里是C++代码: extern"C" { void readstep_(char*,void*); } void readstep_(char* inputFile, void* outShape){ STEPControl_Reader reader; reader = STEPControl_Reader(); int succeed = reader.ReadFile(inputFile); if(!succeed){ std::cout << "There was an error with the input file" << std::endl; return; } reader.NbRootsForTransfer(); reader.TransferRoots(); TopoDS_Shape myShape = reader.OneShape(); TopoDS_Shape* myShapePtr = new TopoDS_Shape(); (*myShapePtr) = myShape; outShape = myShapePtr; return; } extern“C”{ 无效读取步骤(字符*,无效*); } void readstep_(char*inputFile,void*outShape){ 步进控制读卡器; 读卡器=步进控制\读卡器(); int succeel=reader.ReadFile(inputFile); 如果(!成功){ std::cout_C++_Fortran_Fortran Iso C Binding - Fatal编程技术网

使用C++;fortran 77中的类对象 有没有一种方法可以通过C++对象来使用FORTRAN 77?例如: C23456 program main write (*,*) 'Hello from FORTRAN 77!' call readstep('cube.stp'//CHAR(0),myshape) stop end 然后将MyStof用作C++对象,它将被保存在FORTRAN中使用的内存中,并将其传递给其他实际使用它的C++函数? 编辑:这里是C++代码: extern"C" { void readstep_(char*,void*); } void readstep_(char* inputFile, void* outShape){ STEPControl_Reader reader; reader = STEPControl_Reader(); int succeed = reader.ReadFile(inputFile); if(!succeed){ std::cout << "There was an error with the input file" << std::endl; return; } reader.NbRootsForTransfer(); reader.TransferRoots(); TopoDS_Shape myShape = reader.OneShape(); TopoDS_Shape* myShapePtr = new TopoDS_Shape(); (*myShapePtr) = myShape; outShape = myShapePtr; return; } extern“C”{ 无效读取步骤(字符*,无效*); } void readstep_(char*inputFile,void*outShape){ 步进控制读卡器; 读卡器=步进控制\读卡器(); int succeel=reader.ReadFile(inputFile); 如果(!成功){ std::cout

使用C++;fortran 77中的类对象 有没有一种方法可以通过C++对象来使用FORTRAN 77?例如: C23456 program main write (*,*) 'Hello from FORTRAN 77!' call readstep('cube.stp'//CHAR(0),myshape) stop end 然后将MyStof用作C++对象,它将被保存在FORTRAN中使用的内存中,并将其传递给其他实际使用它的C++函数? 编辑:这里是C++代码: extern"C" { void readstep_(char*,void*); } void readstep_(char* inputFile, void* outShape){ STEPControl_Reader reader; reader = STEPControl_Reader(); int succeed = reader.ReadFile(inputFile); if(!succeed){ std::cout << "There was an error with the input file" << std::endl; return; } reader.NbRootsForTransfer(); reader.TransferRoots(); TopoDS_Shape myShape = reader.OneShape(); TopoDS_Shape* myShapePtr = new TopoDS_Shape(); (*myShapePtr) = myShape; outShape = myShapePtr; return; } extern“C”{ 无效读取步骤(字符*,无效*); } void readstep_(char*inputFile,void*outShape){ 步进控制读卡器; 读卡器=步进控制\读卡器(); int succeel=reader.ReadFile(inputFile); 如果(!成功){ std::cout,c++,fortran,fortran-iso-c-binding,C++,Fortran,Fortran Iso C Binding,请阅读标签的标签说明,以获得更好的选择。以及那里的许多问题和答案 我将使用星形符号作为通用扩展名 C++: 由于引用传递,它使用指针到指针 fortran: program main integer*8 myshape call readstep('cube.stp'//CHAR(0),myshape) call pass_it(myshape) end subroutine hello write (*,*) 'Hello from FOR

请阅读标签的标签说明,以获得更好的选择。以及那里的许多问题和答案

我将使用星形符号作为通用扩展名

C++:

由于引用传递,它使用指针到指针

fortran:

  program main

    integer*8 myshape

    call readstep('cube.stp'//CHAR(0),myshape)

    call pass_it(myshape)

  end

  subroutine hello
    write (*,*) 'Hello from FORTRAN 77!'
  end subroutine
在32位平台上使用
integer*4
。 (注:停止声明没有理由)

汇编:

g++ f77c++.f f77c++.C -lgfortran


请阅读标签的标签说明,以获得更好的选择,以及许多问题和答案

我将使用星形符号作为通用扩展名

C++:

由于引用传递,它使用指针到指针

fortran:

  program main

    integer*8 myshape

    call readstep('cube.stp'//CHAR(0),myshape)

    call pass_it(myshape)

  end

  subroutine hello
    write (*,*) 'Hello from FORTRAN 77!'
  end subroutine
在32位平台上使用
integer*4
。 (注:停止声明没有理由)

汇编:

g++ f77c++.f f77c++.C -lgfortran


请至少添加一部分C++代码。否则,FORTRAN 2003(在我的腕表时钟上是二十一世纪)更容易,但是在旧FORTRAN中,可以使用整数×4或整数×8作为不透明指针。请至少添加C++代码的一部分。否则,FORTRAN 2003(在我的腕表时钟上是二十一世纪)更容易!但是你也可以在旧的Fortran中使用integer*4或integer*8作为不透明指针。Vladimir F谢谢你的回答!我的代码还不能正常工作。但这确实是一个改进。下面是我如何分配对象
TopoDS\u Shape myShape=reader.OneShape();*Shape=new TopoDS\u Shape()*shape=&myShape;
但是,当我将对象传回C++时,我不确定如何访问数据。这是错误的,您正在传递一个指向堆栈上局部变量
myShape
的指针。在没有局部变量的情况下,像我的示例中那样操作。
*shape=new TopoDS_shape();
**shape=reader.OneShape()
(但更好的方法是制作一个propper RAII构造函数。)您的建议很有效。非常感谢您的帮助,对于任何愚蠢的错误我都很抱歉(我不熟悉双指针:P)仅供记录。我以前的方法是否错误,因为局部变量myShape在函数调用后会被销毁,指针会指向一个已删除的值?确切地说,返回后该值将不存在。Vladimir F感谢您的回答!我的代码还没有完全工作。但这肯定是一个改进。下面是ho我分配对象
TopoDS\u Shape myShape=reader.OneShape();*Shape=new TopoDS\u Shape()*shape=&myShape;
但是,当我将对象传回C++时,我不确定如何访问数据。这是错误的,您正在传递一个指向堆栈上局部变量
myShape
的指针。在没有局部变量的情况下,像我的示例中那样操作。
*shape=new TopoDS_shape();
**shape=reader.OneShape()
(但更好的方法是制作一个propper RAII构造函数。)您的建议很有效。非常感谢您的帮助,对于任何愚蠢的错误我都很抱歉(我不熟悉双指针:P)请注意,我之前的方法是否错误,因为局部变量myShape会在函数调用后被销毁,指针会指向一个已删除的值?确切地说,返回后该值将不存在。