[英]C++/CLI object casting
sort of new in CLI and wrapper making and got a question about pointers and object casting. CLI和包装器制作方面的新功能,并且遇到了有关指针和对象转换的问题。
Header of my native code: 我的本机代码的标题:
class Telegram : public Message
{
public:
Telegram(const Telegram& tele);
int variablesX;
int variablesY;
}
Source of the native code: 本机代码的来源:
Telegram::Telegram(const Telegram& tele) : Message(tele.lenght)
{
variablesX = tele.variablesX;
variablesY = tele.variablesY;
}
And the trying to get into managed code: header: 并尝试进入托管代码:标头:
public ref class TelegramWrapper : public MessageWrapper
{
public:
TelegramWrapper(eoTelegramWrapper^ tel):
private:
Telegram *myTelegram;
}
source: 资源:
TelegramWrapper::TelegramWrapper(TelegramWrapper^ tel) : MessageWrapper(tel->lenght)
{
myTelegram = new Telegram(reinterpreter_cast<Telegram%>(tel));
}
Can compile, no error just in the C# application cannot use because i receive the error: 'TelegramWrapper telegram' is not supported by the language. 可以编译,没有错误,只是在C#应用程序中无法使用,因为我收到错误:该语言不支持“ TelegramWrapper电报”。 I have tried safe_cast too but because of the pointer differencies it is not possible. 我也尝试过safe_cast,但是由于指针差异,这是不可能的。 How could type casting the TelegramWrapper object into Telegram? 如何键入将TelegramWrapper对象转换为Telegram? Thanks for the answers in advance! 预先感谢您的答复!
I'm not all familiar with C++/CLI, but if you're trying to make a wrapper then you should wrap instead of cast (unless I'm missing something obvious). 我对C ++ / CLI并不十分熟悉,但是如果您要包装,则应该包装而不是包装(除非我遗漏了一些明显的东西)。
public ref class TelegramWrapper : public MessageWrapper
{
public:
TelegramWrapper(TelegramWrapper^ tel);
TelegramWrapper(const &Telegram tel);
private:
Telegram *myTelegram;
property int MyVariablesX {
public: int get { return myTelegram->someVariablesX; }
public: void set(int value) { myTelegram->someVariablesX = value; }
}
property int MyVariablesY {
public: int get { return myTelegram->someVariablesY; }
public: void set(int value) { myTelegram->someVariablesY = value; }
}
};
TelegramWrapper::TelegramWrapper(TelegramWrapper^ tel) : MessageWrapper(tel->Lenght)
{
myTelegram = tel->myTelegram;
}
TelegramWrapper::TelegramWrapper(const &Telegram tel) : MessageWrapper(tel.lenght)
{
myTelegram = tel;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.