本文介绍了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,. ???)

推荐答案


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

07-24 23:43