zoukankan      html  css  js  c++  java
  • c++ windows error C2662 C2663


    //z 2014-08-12 12:39:50 L.141'40810 BG57IV3@XCL T961939060 .K.F37272252  [T14,L639,R15,V232]
    VC C++ windows error C2662 C2663

    在const成员函数中调用如下语句时:
    CBitmap *pOldBitmap = m_dc.SelectObject(&bmpIcon);

    出现了以下错误:
    error C2663: “CDC::SelectObject”: 7 个重载没有“this”指针的合法转换
    其他语句也出现了下列错误:
    error C2662: “CDC::SetStretchBltMode”: 不能将“this”指针从“const CDC”转换为“CDC &”
    转换丢失限定符
    error C2662: “CDC::StretchBlt”: 不能将“this”指针从“const CDC”转换为“CDC &”
    转换丢失限定符
    error C2663: “CDC::SelectObject”: 7 个重载没有“this”指针的合法转换
    //z 2014-08-12 12:39:50 L.141'40810 BG57IV3@XCL T961939060 .K.F37272252  [T14,L639,R15,V232]

    msdn 上 vc2013 的说明也比较清楚。还有例子。
    c2663
    tion' : number overloads have no legal conversions for 'this' pointer

    The compiler could not convert this to any of the overloaded versions of the member function.

    This error can be caused by invoking a non-const member function on a const object. Possible resolutions:

    1. Remove the const from the object declaration.

    2. Add const to one of the member function overloads.

    The following sample generates C2663:

    // C2663.cpp
    struct C {
       void f() volatile {}
       void f() {}
    };
    
    struct D {
       void f() volatile;
       void f() const {}
    };
    
    const C *pcc;
    const D *pcd;
    
    int main() {
       pcc->f();    // C2663
       pcd->f();    // OK
    }


    C2662
    'function' : cannot convert 'this' pointer from 'type1' to 'type2'

    The compiler could not convert the this pointer from type1to type2.

    This error can be caused by invoking a non-const member function on a const object. Possible resolutions:

    • Remove the const from the object declaration.

    • Add const to the member function.

    The following sample generates C2662:

    // C2662.cpp
    class C {
    public:
       void func1();
       void func2() const{}
    } const c;
    
    int main() {
       c.func1();   // C2662
       c.func2();   // OK
    }

    When compiling with /clr, you cannot call a function on a const or volatile qualified managed type. You cannot declare a const member function of a managed class, so you cannot call methods on const managed objects.

    // C2662_b.cpp
    // compile with: /c /clr
    ref struct M {
       property M^ Type {
          M^ get() { return this; }
       }
    
       void operator=(const M %m) {
          M ^ prop = m.Type;   // C2662
       }
    };
    
    ref struct N {
       property N^ Type {
          N^ get() { return this; }
       }
    
       void operator=(N % n) {
          N ^ prop = n.Type;   // OK
       }
    };

    The following sample generates C2662:

    // C2662_c.cpp
    // compile with: /c
    // C2662 expected
    typedef int ISXVD;
    typedef unsigned char BYTE;
    
    class LXBASE {
    protected:
        BYTE *m_rgb;
    };
    
    class LXISXVD:LXBASE {
    public:
       // Delete the following line to resolve.
       ISXVD *PMin() { return (ISXVD *)m_rgb; }
    
       ISXVD *PMin2() const { return (ISXVD *)m_rgb; };   // OK
    };
    
    void F(const LXISXVD *plxisxvd, int iDim) {
       ISXVD isxvd;
       // Delete the following line to resolve.
       isxvd = plxisxvd->PMin()[iDim];
    
       isxvd = plxisxvd->PMin2()[iDim];  
    }

    @IS2120#CNBLOGS.T2169364049[T1,L65,R1,V259]:备忘
    $ € ₤ ₭ ₪ ₩ ₮ ₦ ₱ ฿ ₡ ₫ ﷼ ¥ ﷼ ₫ ₡ ฿ ₱ ₦ ₮ ₩ ₪ ₭ ₤ € $
  • 相关阅读:
    关于分工协作
    SQL分类后每类随机抽取
    新浪微群抢票
    to learn softwarelist
    大厂程序员教你如何学习C++(内附学习资料)
    干货|大厂程序员来讲一下互联网公司技术面试的流程以及注意事项
    程序员要如何写简历(附简历模板)
    laravel项目拉取下来安装,node.js库安装
    laravelhas方法查看关联关系
    laravel框架少见方法详解
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745635.html
Copyright © 2011-2022 走看看