【问题标题】:error C3767: candidate function(s) not accessible Visual Studio 2010错误 C3767:候选函数无法访问 Visual Studio 2010
【发布时间】:2012-09-17 22:13:26
【问题描述】:

我收到此错误:

error C3767: 'phys1::point::get_prev': candidate function(s) not accessible

这是我的代码

物理.h

using namespace System;

namespace phys1 {

  typedef struct position{
    int x;
    int y;
  } pos;

 public ref class point{
   public:
     point(float speed, float gr);
   public:  
     pos get_prev();
   public: 
     pos get_next();
 };
}

phys.cpp

// This is the main DLL file.
#include "phys.h"

using namespace System;

namespace phys1 {
     ...
  static pos point::get_prev(){
    pos point;
    point.x=x;
    point.y=y;
    return point;
  }
    ...
}

我尝试在库中使用的结构是否有问题?我可以用其他方式构建它吗?

【问题讨论】:

  • static 来自哪里?它不在类内的声明中!

标签: struct c++-cli


【解决方案1】:

您正在混合使用 C++ 语法和 C++/CLI 语法。 “结构”是本机定义(C++ 的)。

要声明“结构”,最好使用“值结构”结构。

“不可访问”错误也可能是由于“位置”被隐式声明为“私有”。

在此处查看有关托管类型声明的更多信息:http://www.codeproject.com/Articles/17741/C-CLI-in-Action-Declaring-CLR-types

【讨论】:

    【解决方案2】:

    如果您尝试跨程序集边界传递 pos 类型的值,则它应该是公共托管类型。 public value struct pos 最适合您的工作。

    默认情况下,原生类型在程序集边界上是不可见的,使它们可见的#pragma 与其说是真正的解决方案,不如说是一个杂物。只需使用元数据创建一个适当的 .NET 类型。

    【讨论】:

      猜你喜欢
      • 2010-10-31
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多