error C2440: 'type cast' : cannot convert from 'struct IDispatch *' to 'class CsgGrid'
        No constructor could take the source type, or constructor overload resolution was ambiguous
  我想是不是要在改cpp文件头少了一个头文件?
                                         谢谢

解决方案 »

  1.   

    编译器无法从“type1”转换为“type2”。将用 Incompatible calling conventions for UDT return value 消息限定此示例代码 15 和 16 行的 C2440 错误。(UDT 指用户定义的类型,如类、结构或联合。)在前向声明的返回类型中指定的 UDT 调用约定与该 UDT 的实际调用约定有冲突,而且涉及函数指针时,会导致上述类型的不兼容错误。 在该示例中,我们首先拥有某结构和返回该结构的函数的前向声明;编译器假定该结构使用 C++ 调用约定。然后我们生成该结构的定义,默认情况下,该结构定义使用 C 调用约定。因为编译器在读完整个结构前,不知道该结构的调用约定,所以也假定在 get_c2 的返回类型中该结构的调用约定为 C++。该结构后面跟有另一个返回该结构的函数声明,但在此时,编译器知道该结构的调用约定为 C++。同样,返回该结构的函数指针在结构定义之后定义,所以编译器知道该结构使用 C++ 调用约定。因为将应使用 C 调用约定返回类型的函数指针赋予了应使用 C++ 调用约定返回类型的函数,所以发生错误。若要解决由于不兼容的调用约定而产生的 C2440,请在 UDT 定义之后声明返回 UDT 的函数。
      

  2.   

    // C2440.cpp
    struct MyStruct;MyStruct get_c1();struct MyStruct
    {
       int i;
       static MyStruct get_C2();
    };MyStruct get_C3();typedef MyStruct (*FC)();FC fc1 = &get_c1;   // C2440, line 15
    FC fc2 = &MyStruct::get_C2;   // C2440, line 16
    FC fc3 = &get_C3;class CMyClass {
    public:
       explicit CMyClass( int iBar)
          throw()   {
       }   static CMyClass get_c2();
    };int main() {   CMyClass myclass = 2;   // C2440
       // try one of the following
       // CMyClass myclass(2);
       // CMyClass myclass = (CMyClass)2;   int *i;
       float j;
       j = (float)i;   // C2440, cannot cast from pointer to int to float
    }
      

  3.   

    当运行下面程序时就产生
    CsgGrid CsgColumns::GetGrid()
    {
    LPDISPATCH pDispatch;
    InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_DISPATCH,   (void*)&pDispatch, NULL);
    return CsgGrid(pDispatch);
    }
    上面的问题