C++ map给出类型转换错误,但仅在为x86编译时出现

C++ map给出类型转换错误,但仅在为x86编译时出现,c++,c++11,x86,stdmap,C++,C++11,X86,Stdmap,使用Visual Studio 2017,我有一段代码定义了一个std::map,它在x64中编译良好,但在为x86编译时返回错误 有问题的映射在枚举上设置键,并返回带有描述符字符串和一些函数指针的结构 我通过了我的项目设置,确认了我的C++编译器设置中唯一的区别是两个架构标志。我最好的猜测是它与每个映射条目中的函数指针有关,因为我在同一个文件中有其他std::map,其中包含字符串结构和double/float,它们都可以正常工作 引发的特定错误是C2440:无法从type1转换为type2,

使用Visual Studio 2017,我有一段代码定义了一个std::map,它在x64中编译良好,但在为x86编译时返回错误

有问题的映射在枚举上设置键,并返回带有描述符字符串和一些函数指针的结构

我通过了我的项目设置,确认了我的C++编译器设置中唯一的区别是两个架构标志。我最好的猜测是它与每个映射条目中的函数指针有关,因为我在同一个文件中有其他std::map,其中包含字符串结构和double/float,它们都可以正常工作

引发的特定错误是C2440:无法从type1转换为type2,文本无法从“初始值设定项列表”转换为std::map

编辑: 我做了一个没有任何外部依赖的最紧凑的例子。x64中没有错误,但设置为x86时会出现类型转换错误:

#include <map>

typedef double(*convertFunc)(int, int, double);
typedef int(*convertFuncD)(int, int, double*,double*,int);

extern "C" {
    __declspec(dllexport) double __stdcall Pressure(
        int inUnits,
        int outUnits,
        double inValue
    );

    __declspec(dllexport) int __stdcall PressureD(
        int inUnits,
        int outUnits,
        double* inValue,
        double* outValue,
        int n
    );
}

//Metadata for each Property
struct PropertyMetaData {
    const char desc[20]; //Text description
    const convertFunc func; //double conversion function
    const convertFuncD funcArrayD; //array double conversion function
};

// Map containing all of the properties and their metadata
typedef std::map<int, PropertyMetaData> PropertiesMap;

const PropertiesMap conversions = {
    //Mapping The type of unit (mass, distance, etc.) to the appropriate function

    //Enumeration                   {desc[20],      func,        arrayfuncD,   arrayFuncF   }
    { 1,    {"Pressure",    Pressure,    PressureD}},
};

经过更多的实验,它似乎是由u stdcall限定符引起的。如果删除了,我对这两种体系结构都没有问题。

明白了!问题在于函数声明中包含了u stdcall,或者更确切地说,函数指针类型定义中省略了u stdcall。似乎对于某些体系结构组合,u stdcall可能会或可能不会导致类型转换错误,如果u stdcall不在指针类型定义中。声明我的函数指针类型如下:

typedef double(__stdcall *convertFunc)(EUnits, EUnits, double);
typedef int(__stdcall *convertFuncD)(EUnits, EUnits, double*,double*,int);
typedef int(__stdcall *convertFuncF)(EUnits, EUnits, float*, float*, int);

解决了错误

你能把它简化到可以在实际代码中重现吗?我不知道是否需要完整的UnitsConversion.h标头,但我需要它。EUnits和EUnitConversion仍然未定义。请尝试制作一个生成错误的代码块。您可以删除内容:@谢谢你的回复!我做了一个简短的示例代码,一路上发现了一些关于错误原因的线索。PressureD应该返回int还是double?@o11c当我复制标题时,这是一个错误。我正在修好它。。。此外,如果创建PropertyMetaData实例,则会收到一条更有用的错误消息。没有来自std::map的与模板相关的错误