C ++-重新定义问题(托管包装) [英] C++ - Redefinition Issues (Managed Wrapper)

查看:101
本文介绍了C ++-重新定义问题(托管包装)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试为本机类创建托管包装时,我遇到重新定义错误.

我做了很多重写,重命名了一些与.Net命名方案相冲突的内容,并将其减少为一个链接错误.

该错误说明:重新定义了私有静态DWORD myPtr.

因此,我有两个类,一个是声明静态myPtr的本机类,另一个是不执行任何操作但引用本机类的存根托管类.
我尝试将代码减少到最低限度.

I''m getting redefinition errors when trying to make a managed wrapper for a native class.

I did a bunch of rewriting, renamed some stuff that conflicted with .Net naming schemes, and have reduced this to one single linking error.

The error is stating that: private static DWORD myPtr is redefined.

So, I have two classes, one native class declaring a static myPtr, and a stub managed class that does nothing, but reference the native class.

I tried reducing the code to the minimum.

#pragma once

class MyClass
{
    private:
        static DWORD myPtr;
};







#pragma once
#pragma unmanaged
#include "MyClass.h"
#pragma managed

#using <mscorlib.dll>
using namespace System;

public ref class MyClassNet
{
    public:
        MyClassNet(){};
        ~MyClassNet(){};
};



不会出现同样的错误,从托管类中注释掉.h文件,可以消除该错误. (这两个类都是各自工作,将它们放在一起,会发生灾难.)

---

好的,所以,我换出了DWORD,并保持了无符号的长久,现在它可以工作了……(无论如何,它都会进行编译,我将对其进行进一步测试,并确保在我将其称为我的解决方案之前,所有内容都可以正常工作.) />
这是一个真正的BS,浪费了所有时间,因为他们无法正确解析typedef,我几乎希望它没有被修复,因为这很愚蠢……(以及如何将其转换为链接错误,重新定义)等等)???)



Nothing, same error, commenting out the .h file from the managed class, removes the error. (Both classes work on their own, put them together, catastrophuck occurs.)

---

Okay, so, I swapped out DWORD, for unsigned long, and now it works... (It compiled anyways, I''m going to test this further and make sure everything actually works before I call this my solution.)

This is some real BS, waste all that time because they can''t resolve a typedef properly, I almost hope it isn''t fixed, because this is stupid... (And how does that translate to a linking error, redefinition, etc,. ???)

推荐答案

好吧,事实证明,MSVC ++ 2010 Express \ C ++ \ CLI或其他任何类型(VS2010Exp)都不喜欢typedefs ,并且对静态成员也不太在意,我将本机类重写为单例,并将有问题的成员变量从DWORD更改为无符号long(非静态),并且一切都很好,我的托管函数现在可以正常执行.

很好玩,让我们再也不做了,mmmkay?
Well, turns out, MSVC++ 2010 Express\C++\CLI, or whatever(VS2010Exp), doesn''t like typedefs, and it doesn''t much care for static members either, I rewrote my native class as a singleton, and changed the offending member variable from a DWORD to an unsigned long(non-static), and all is well in the world, my managed function executes fine now.

That was fun, let''s never do it again, mmmkay?


这篇关于C ++-重新定义问题(托管包装)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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