.Net类库中的公共构造函数->控制台应用程序中的私有成员访问错误 [英] Public constructor in .Net class library --> Private member access error in Console Application
问题描述
我正在尝试包装非常讨厌的本机c ++图像处理库的一部分,以便在托管代码中使用.但是几行之后,我遇到了以下问题.
首先是代码:
我的头文件:
I am trying to wrap part of a very nasty native c++ image processing library to be usable in managed code. However just after a few lines I encountered the following probem.
First of all the code:
My header file:
namespace HalconWrapper {
public ref class ATMHTuple
{
public:
ATMHTuple();
ATMHTuple(int);
ATMHTuple(double);
ATMHTuple(String^);
ATMHTuple(ATMHTuple^);
ATMHTuple(Hlong);
ATMHTuple(HTuple*);
ATMHTuple(ICollection<int>^);
ATMHTuple(ICollection<double>^);
ATMHTuple(ICollection<String^>^);
ATMHTuple(Hlong, int);
ATMHTuple(Hlong, double);
ATMHTuple(Hlong, String^);
ATMHTuple(Hlong, HTuple*);
ATMHTuple(ATMHTuple^, ATMHTuple^);
ATMHTuple(HTuple*, HTuple*);
~ATMHTuple();
property HTuple* T
{
HTuple* get() { return tuple; }
void set (HTuple* value) { tuple = value; }
}
private:
HTuple* tuple;
};
}
其中一个构造函数的简单实现:
One simple implementation of one of the constructors:
ATMHTuple::ATMHTuple(HTuple* value)
{
tuple = new HTuple(*value);
}
请不要告诉我使用"HTuple&价值",我知道这是更好的方法.到目前为止,我只是尝试了很多事情,用指针替换引用就是其中之一.
正如您已经猜到的那样,HTuple是我希望包装的本机类型.这是一个具有联合作为成员的类,用于容纳"long(*)","double(*)"或"char *(*)".
MY问题:库编译正常.在我的测试应用程序中,我可以调用所有使用标准值类型或托管类型作为参数的构造函数.但是,一旦我开始调用具有HTuple *(或者当我仍在使用"pass-by-reference")作为参数的HTuple的构造函数时,在编译时就会出现以下错误:
测试应用:
Please do not tell me to use "HTuple& value", I know that it is the better way. I just tried a lot of things so far and replacing references by pointers was one of them.
As you already have guessed HTuple is the native type I wish to wrap. It is a class which has a union as member to hold "long(*)", "double(*)", or "char*(*)".
MY PROBLEM: The library compiles fine. In my test-application I can call all constructors that use standard value types or managed types as arguments. But as soon as I start calling constructors having HTuple* (or just HTuple, when I was still using "pass-by-reference") as arguments I get the following error at compile time:
Test app:
#include "HalconCpp.h"
using namespace System;
using namespace Halcon;
using namespace HalconWrapper;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Initializing Tuples");
HTuple t1(3l);
HTuple t2(2l);
ATMHTuple(3); //no errors
Console::WriteLine(L"Concatenating Tuples");
tuple_concat(t1, t2, &t1);
Console::WriteLine(L"Causing Exception");
try
{
ATMHTuple^ ht = gcnew ATMHTuple(&t1); //compiler error
}
catch(ATMHTupleException^ e)
{
Console::WriteLine(e->Message);
}
Console::WriteLine(L"End Of Program.");
Console::ReadKey();
return 0;
}
错误1错误C2248:'HalconWrapper :: ATMHTuple :: ATMHTuple':无法访问在类'HalconWrapper :: ATMHTuple'中声明的私有成员
我要包装的类来自静态库.这是问题的原因吗?
是否有可能不允许包装该库?
请给我提示一下可能是什么问题以及如何解决(至少要看哪里).
Martin
请给我您的知识----请!
Error 1 error C2248: 'HalconWrapper::ATMHTuple::ATMHTuple' : cannot access private member declared in class 'HalconWrapper::ATMHTuple'
The class I am trying to wrap is coming from a static library. Is this the cause of the problem?
Is there a possibility that the library does not allow to be wrapped?
Please give me a hint on what could be the problem and how I can solve it (at least where to look).
Martin
Give me your knwledge ---- please!
推荐答案
我看不到,您将ATMHTuple(HTuple *)构造函数声明为公共.它与静态库无关,它是编译时错误.我想到的就是获取错误的头文件.如果您希望有人看一下,请将repro项目发布到文件共享服务.
I don't see it, you declared the ATMHTuple(HTuple*) constructor public. Its got nothing to do with static libraries, its a compile time error. Getting the wrong header file is all I can think of. Post a repro project to a file sharing service if you want somebody to take a look at this.
这篇关于.Net类库中的公共构造函数->控制台应用程序中的私有成员访问错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!