错误:从积分类型到指针类型的转换需要reinterpret_cast,C样式转换或函数样式转换

时间:2013-12-23 19:21:04

标签: c++ pointers casting

我使用变量RockElem获得了强制转换错误。变量在类中定义,其他变量是整数。该变量定义为const。

    if(resistivitySolve)
        fileName << "_resist";
    else if(dynamic_cast< const Water* >(fluid) != 0)
        fileName << "_water";
    else
        fileName << "_oil";

    fileName << "_sw_" << waterSat*100.0;

    sort(m_throatConductances.begin(), m_throatConductances.end(), throatIndexCompare());
    pair<const RockElem*, double> dummy(0, 0.0);
    int idx(-99);
    for(size_t i = 0; i < m_throatConductances.size(); ++i)
    {
        int tmp(m_throatConductances[i].first->orenIndex());
        if(tmp == idx) m_throatConductances[i] = dummy;
        idx = tmp;
    }

我得到的错误是 错误C2440:'初始化':无法从'int'转换为'const RockElem *' 1 GT;从整数类型到指针类型的转换需要reinterpret_cast,C风格的转换或函数式转换


错误在于类的这一部分 - 在术语RockElem *

之前使用const
       [
          _Ty1=const RockElem *,
          _Ty2=double,
          _Ty=int,
          _Other1=int,
          _Other2=double
       ]

参见函数模板实例化'std :: _ Pair_base&lt; _Ty1,_Ty2&gt; :: _ Pair_base&lt; _Ty,double&gt;(_ Other1&amp;&amp;,_ Other2&amp;&amp;)'正在编译


使用它的代码行是

           pair<RockElem*, double> dummy(0, 0.0);

这设置不正确吗?

1 个答案:

答案 0 :(得分:0)

错误消息

  

错误C2440:'初始化':无法从'int'转换为'const   RockElem *'1&gt;

很清楚。您正在尝试将整数类型的对象转换为指针RockElem *。你确定你要这么做吗?如果是,请遵循您在错误消息中提供的编译器的建议。

相关问题