typedef : 'Integer': 重新定义;不同的基本类型

问题描述

我有一个包含 dll 和应用程序的项目。 dll 声明了一个 typedef,名称为 Number for int,应用程序也有一个 typedef 定义为 typedef unsigned int Number;

现在 dll 和应用程序都可能出于不同的目的使用这个 typedef。应用程序正在导入此 dll 以供使用。

但是在构建应用程序时,我们收到错误 redefinition; different basic types

我为此制作了最少的工作示例:

项目结构:

enter image description here

Calculations.h(dll算术的一部分)

#pragma once

#ifdef ARITHMETIC_EXPORTS
#define ARITHMETIC_API __declspec(dllexport)
#else
#define ARITHMETIC_API __declspec(dllimport)
#endif

typedef int Number;


ARITHMETIC_API int AddIntImpl(Number a,Number b);

Calculations.cpp(dll算术的一部分)

#include "Calculations.h"


int AddIntImpl(Number a,Number b)
{
    return a + b;
}

Main.h(应用程序)

#pragma once

typedef unsigned int Number;

Main.cpp(应用程序)

#include <Calculations.h>
#include "Main.h"
#include <iostream>

using namespace std;

int main()
{
    Number val = 1;
    int a = 5,b = 6;
    cout << AddIntImpl(a,b);
    cin.get();
}

在构建 dll 时它运行良好,但是在构建应用程序时我得到

enter image description here

那么我如何告诉编译器仅在该 dll 中使用在 dll 中声明的 Number 并且该 typedef 不会在任何其他 dll/应用程序或其他导入它的程序中使用

注意:这个问题与已经提出的问题不同。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)