为什么“候选功能不可用”?虽然宣布公开 [英] why is "candidate function(s) not accessible" although declared public

查看:95
本文介绍了为什么“候选功能不可用”?虽然宣布公开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调用某些成员时遇到编译错误候选函数无法访问,尽管我将它们声明为 public
仅当涉及到 vtk 中的某个类(作为返回类型或作为参数)时,我才会收到错误消息当要调用的类与调用代码不在同一VS项目中时。我也尝试了其他没有运气的vtk类型:(

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 :(

下面是一些测试代码:

// 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();
};

我试图从同一项目中调用函数 B 就像这样:

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

如何解决此错误?为什么只在vtk类型上出现?

How I can resolve this error? Why does it occur only on vtk-types?

亲切的问候,
丰富

kind regards, richn

推荐答案

C3767文档和社区评论显示:


另一种错误发生方案

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.

这里的解决方案是在本机类型上添加#pragma make_public,在定义本机类型之后但在定义使用它的托管方法
之前,添加
。 #pragma make_public的文档暗示,当
a公共托管类型公开非公共本机类型时,应该假定
会收到编译器警告,但$ b(至少具有默认警告级别) $ b似乎并非如此。

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.

您是否检查了该建议?

这篇关于为什么“候选功能不可用”?虽然宣布公开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆