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]:备忘
    $ € ₤ ₭ ₪ ₩ ₮ ₦ ₱ ฿ ₡ ₫ ﷼ ¥ ﷼ ₫ ₡ ฿ ₱ ₦ ₮ ₩ ₪ ₭ ₤ € $
  • 相关阅读:
    数字滤波器
    PCL点云库:Kd树
    KNN算法与Kd树
    分布式锁与实现(一)——基于Redis实现
    Redis分布式锁的正确实现方式
    redis常用命令大全
    使用 Redis 实现排行榜功能
    RabbitMQ下的生产消费者模式与订阅发布模式
    java高级精讲之高并发抢红包~揭开Redis分布式集群与Lua神秘面纱
    Java进阶面试题大集合-offer不再是问题
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745635.html
Copyright © 2011-2022 走看看