问题描述
我有一个Assembly(A),它定义了一个Managed类,它有一个公共的构造函数,它接受两个本地类型。
I have an Assembly(A) which defines a Managed class which has a public constructor that takes two native types.
我可以访问Header文件和编译
I have access to the Header files and compiled lib files which contain the native types.
我创建了一个 C ++ / CLI
项目,并定义了一个 ref class
,它包含一个返回在(A)中定义的公共类型的单个 public:static
方法。
I created a C++/CLI
project and defined a ref class
which contains a single public: static
method that returns a public type defined in (A).
当我试图通过传递一个原生类型,我收到了'C3767'YourType :: TypeB':候选函数不可访问。
When I try to contstruct by passing in a native type I receive the `C3767 'YourType::TypeB': Candidate function(s) not accessible.
我添加了 #pragma make_public(Type)
用于原生类型及其派生但仍然不快乐的任何类型。
I've added #pragma make_public(Type)
for the native types and any type they derive from but still not joy.
我的类标题:
#pragma once
#include "StdAfx.h"
using namespace System;
using namespace AssemblyA;
namespace NativeWrapper {
ref class MyFactory
{
public:
static AssemblyAType^ Build();
};
}
我的cpp文件:
#include "StdAfx.h"
#pragma make_public(nativeObjectRoot)
#pragma make_public(nativeObjectDerived)
#include "MyFactory.h"
using namespace System;
using namespace NativeWrapper;
AssemblyAType^ MyFactory::Build()
{
nativeObjectDerived* myNativeObject;
//myNativeObject initialised and set up here
return gcnew AssemblyAType(myNativeObject); <--C3767
}
我看过和托管类型Assembly有一个带有这个签名的公共构造函数。似乎不能让编译指示工作?
I've looked and the managed type `AssemblyAType' has a public constructor with this signature. Can't seem to get the pragma to work??
所以总结一下。
我的C ++ / CLI项目引用定义在其构造函数中接受本机类型的类型的第三方程序集。我的项目也有头/ lib文件添加/链接到。
My C++/CLI project references a 3rd party Assembly that defines a type which takes a native type in its constructor. My project also has the header/lib files added/linked to.
注意:我上面的代码不是我已经得到,但我已经剥离相关部分。
Note: my code above isn't exactly what I've got but I've stripped out the pertinent parts.
推荐答案
make_public将使原生类型可见于使用它的程序集的使用者:。它不会更改您引用的程序集中的可见性。
make_public will make the the native type visibile to consumers of the assembly where you use it: http://msdn.microsoft.com/en-us/library/ms235607(v=vs.80).aspx. It will not change the visibility in an assembly you reference.
似乎你引用的程序集应该有一个本地类型的make_public,或者简单地声明为本地类型public(见)。
It seems the assembly you referenced should have had either a make_public for the native type, or simply declared the native type public (see Type visibilty for a header Share a header file shared between native and managed clients).
下面的页面似乎表明他们应该得到一个警告,写入方法,而不使本机类型公开:
The below page seems to indicate that they should have gotten a warning for writing the method without making the native types public: http://msdn.microsoft.com/en-us/library/ms173713(v=vs.80).aspx
也许您可以发布第三方AssemblyCype代码,以确保没有其他的东西。
Perhaps you could post the third-party AssemblyAType code to make sure there's nothing else we're missing.
这篇关于添加#pragma make_public(类型)不会删除C3767错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!