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]:备忘
    $ € ₤ ₭ ₪ ₩ ₮ ₦ ₱ ฿ ₡ ₫ ﷼ ¥ ﷼ ₫ ₡ ฿ ₱ ₦ ₮ ₩ ₪ ₭ ₤ € $
  • 相关阅读:
    UVA 10564 Paths through the Hourglass DP
    HDU 3397 Sequence operation 线段树 成段更新 区间合并
    HDU 3308 LCIS 线段树 单点更新+区间合并
    POJ 3667 Hotel 线段树 区间合并
    UVALive 3942 Remember the Word Tire+DP
    POJ 1703 Find them, Catch them
    UVA 1366 Martian Mining DP
    UVA 1456 Cellular Network 贪心+DP
    UVA 11573 Ocean Currents
    【ACM】hdu_zs1_1003_放大的X _201307271557
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745635.html
Copyright © 2011-2022 走看看