Bc4.5 to VC6

F

Francis Goblet

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_ERROR,
IFACE_RESTORE_ERROR,
IFACE_TIME_OUT,
IFACE_DRIVER_TEST_ERROR,
IFACE_WRITE_ERROR,
IFACE_UNDEFINED_ERROR
};

// Exception handling class
class IfaceError : public ClassError
{
public:
IfaceError(IFACE_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==(const 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(const Interface&);

/*
Header : intface.cpp
*/

#include "intface.h"

// Static member initialisation
int Interface::RiscTimeOut;

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

// Design class : Interface
Interface::eek:perator==(const Interface& inter)
{
return name==inter.getName();
}

\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(const 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::IfaceError(IFACE_ERROR code, char *module="", char *object="",
char *method="", unsigned int line=0) :
exceptionCode(code),
ClassError(module,object,method,line)
{
}
 
R

Russell Hanneken

Francis said:
RWCString& Interface::getName(void)
{
return name;
}

// Design class : Interface
Interface::eek:perator==(const Interface& inter)
{
return name==inter.getName();
}

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

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::getName(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;
// . . .
};
// Design hash function for Interface object
unsigned hashInterface(const 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

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

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

Hope that helps,

Russell Hanneken
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top