Bc4.5 to VC6

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Francis Goblet

    Bc4.5 to VC6

    Hello !

    I have to port one DLL written in BC++ 4.5 to VC 6.

    Some code don't port correctly and I have some difficulties with the
    following lines which are not correctly interpreted in VC6

    I have included hereafter the .h and .cpp involved and the errors produced
    !

    what's wrong ? thanks !
    --------
    /*
    Header : intface.h
    */

    // Exception handling constants
    enum IFACE_ERROR {
    IFACE_INIT_ERRO R,
    IFACE_RESTORE_E RROR,
    IFACE_TIME_OUT,
    IFACE_DRIVER_TE ST_ERROR,
    IFACE_WRITE_ERR OR,
    IFACE_UNDEFINED _ERROR
    };

    // Exception handling class
    class IfaceError : public ClassError
    {
    public:
    IfaceError(IFAC E_ERROR, char*, char*, char*, unsigned int);
    IFACE_ERROR exceptionCode;
    };

    /* Definition des types d'erreurs */
    enum { RISC_OK = 0, BAD_ECHO, TIME_OUT, DEFAULT_DRIVER };

    // Design class
    class Interface
    {
    public:
    Interface(void) { slaveBit = 0; };
    virtual ~Interface(){};
    int operator==(cons t Interface&);
    virtual void InitCom (int)=0;
    virtual void RestoreCom (void)=0;
    RWCString& getName(void);
    static int RiscTimeOut;
    int isSlave (void) { return slaveBit; };
    void setIsSlave (void) { slaveBit = 1; }
    protected:
    RWCString name;
    int slaveBit;
    };

    // Design hash function for Interface object
    unsigned hashInterface(c onst Interface&);

    /*
    Header : intface.cpp
    */

    #include "intface.h"

    // Static member initialisation
    int Interface::Risc TimeOut;

    RWCString& Interface::getN ame(void)
    {
    return name;
    }

    // Design class : Interface
    Interface::oper ator==(const Interface& inter)
    {
    return name==inter.get Name();
    }

    \INTFACE.CPP(39 ) : error C2662: 'getName' : cannot convert 'this' pointer
    from 'const class Interface' to 'class Interface &' Conversion loses
    qualifiers

    // Design hash function for Interface object
    unsigned hashInterface(c onst Interface& iface)
    {
    return iface.getName() .hash();
    }
    \INTFACE.CPP(51 ) : error C2662: 'getName' : cannot convert 'this' pointer
    from 'const class Interface' to 'class Interface &' Conversion loses
    qualifiers
    \INTFACE.CPP(51 ) : error C2228: left of '.hash' must have class/struct/union
    type

    // Design class : IfaceCanError
    IfaceError::Ifa ceError(IFACE_E RROR code, char *module="", char *object="",
    char *method="", unsigned int line=0) :
    exceptionCode(c ode),
    ClassError(modu le,object,metho d,line)
    {
    }

    --
    Francis

  • Russell Hanneken

    #2
    Re: Bc4.5 to VC6

    Francis Goblet wrote:[color=blue]
    >
    > RWCString& Interface::getN ame(void)
    > {
    > return name;
    > }
    >
    > // Design class : Interface
    > Interface::oper ator==(const Interface& inter)
    > {
    > return name==inter.get Name();
    > }
    >
    > \INTFACE.CPP(39 ) : error C2662: 'getName' : cannot convert 'this' pointer
    > from 'const class Interface' to 'class Interface &' Conversion loses
    > qualifiers[/color]

    The "inter" parameter is const, but you invoke its "getName" member
    function, which is not const, and therefore (as far as the compiler knows)
    might try to modify inter's state. Try making getName a const member
    function, like this:

    RWCString& Interface::getN ame(void) const
    {
    return name;
    }

    Note the keyword "const" appears at the end of the function header. You
    must also add the "const" keyword to the end of the function declaration
    within the Interface class definition:

    class Interface
    {
    // . . .
    RWCString& getName(void) const;
    // . . .
    };
    [color=blue]
    > // Design hash function for Interface object
    > unsigned hashInterface(c onst Interface& iface)
    > {
    > return iface.getName() .hash();
    > }
    > \INTFACE.CPP(51 ) : error C2662: 'getName' : cannot convert 'this' pointer
    > from 'const class Interface' to 'class Interface &' Conversion loses
    > qualifiers[/color]

    Same problem. Just make the modification I suggested above, and that should
    fix things.
    [color=blue]
    > \INTFACE.CPP(51 ) : error C2228: left of '.hash' must have
    > class/struct/union type[/color]

    This error might simply be a consequence of the previous error.

    Hope that helps,

    Russell Hanneken
    rhanneken@pobox .com


    Comment

    Working...