我大致有以下情况.我有一个从Fortran代码调用的C++函数,并将函数指针和void指针作为这样的参数
int STDCALL FORTRAN_NAME(CPPFunction, CPPFUNCTION)(
int (*userFunction)(const int *object,
const void *userFunctionUserData),
const void *userData)
{
// ...
int index;
int result;
// ...
result = userFunction(&index, userData);
// ...
}
Run Code Online (Sandbox Code Playgroud)
这是从Fortran这样调用的
! ...
DOUBLE PRECISION, ALLOCATABLE :: data(:,:)
INTEGER :: n, result
! ...
ALLOCATE(data(3,n)); data = 0.0
! ... fill data with something
result = CPPFUNCTION(FORTRANFUNCTION, data)
! ...
Run Code Online (Sandbox Code Playgroud)
我希望通过函数指针传递的Fortran函数看起来像
INTEGER FUNCTION FORTRANFUNCTION(idx, data)
IMPLICIT NONE
INTEGER, INTENT(IN) :: idx
DOUBLE PRECISION, INTENT(IN) :: data(*)
INTEGER :: i, …Run Code Online (Sandbox Code Playgroud) c++ fortran function-pointers language-interoperability void-pointers
在下面的代码A::Type是private在A.
class A {
typedef int Type;
};
void func(int t, A::Type var)
{
return;
}
Run Code Online (Sandbox Code Playgroud)
尝试编译时gcc会出现以下错误.
test.cpp: In function 'void func(int, A::Type)':
test.cpp:12:21: error: 'typedef int A::Type' is private within this context
void func(int t, A::Type var)
^~~~
test.cpp:2:17: note: declared private here
typedef int Type;
^~~~
Run Code Online (Sandbox Code Playgroud)
但是,如果我将第一个参数更改为模板参数,就像这样
template<typename T>
void func(T t, A::Type var)
{
return;
}
Run Code Online (Sandbox Code Playgroud)
类似的访问说明符似乎被忽略,这将编译.
起初我怀疑它可能是一个错误gcc,但MSVC 2015表现出相同的行为.
出于某种原因,这种行为是否需要C++标准?如果是的话,这里的理由是什么?