Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 08:40 PM
Francis Goblet
Guest
 
Posts: n/a
Default 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_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::operator==(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)
{
}

--
Francis

  #2  
Old July 19th, 2005, 08:40 PM
Russell Hanneken
Guest
 
Posts: n/a
Default Re: Bc4.5 to VC6

Francis Goblet wrote:[color=blue]
>
> RWCString& Interface::getName(void)
> {
> return name;
> }
>
> // Design class : Interface
> Interface::operator==(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[/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::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;
// . . .
};
[color=blue]
> // 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[/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


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles