问题
I am getting compile error candidate function(s) not accessible
when calling certain members, although I declared them as public
.
I only get the error when some class from vtk is involved (as return type or as argument) and when the class to be called is not in the same VS-project as the calling code. I also tried other vtk types with no luck :(
Here is some test code:
// A.h, in a seperate class library
#include <vtkActor.h>
public ref class A
{
public:
A(void);
void test1(vtkActor* actor);
vtkActor* test2();
void test3(char* actor);
char* test4();
};
// B.h, Same as A but in the same project as the calling code
#include <vtkActor.h>
ref class B
{
public:
B(void);
void test1(vtkActor* actor);
vtkActor* test2();
void test3(char* actor);
char* test4();
};
I tried to call the functions from the same project B
is in like this:
// calls to class library
A^ testA = gcnew A();
testA ->test1(vtkActor::New()); // error
testA ->test2(); // error
testA ->test3(""); // ok
testA ->test4(); // ok
// calls to this project
B^ testB = gcnew B();
testB ->test1(vtkActor::New()); // ok
testB ->test2(); // ok
testB ->test3(""); // ok
testB ->test4(); // ok
In the two lines with //error this is the exact message:
error C3767: 'A::test1': candidate function(s) not accessible
How I can resolve this error? Why does it occur only on vtk-types?
kind regards, richn
回答1:
A short look at C3767 documentation and the community comments shows:
Another error-generating scenario
Another thing that seems to generate this error is using a native type in the signature of a public method, and then trying to call that method from a different assembly.
The solution here is to add a #pragma make_public on the native type, after defining the native type but before defining the managed method that uses it. The docs for #pragma make_public imply you're supposed to get a compiler warning when a non-public native type is exposed by a public managed type, but (at least with the default warning levels) that does not seem to be the case.
Did you check that suggestion?
来源:https://stackoverflow.com/questions/8400176/why-is-candidate-functions-not-accessible-although-declared-public