C2662 Error

D

dushkin

Hi,

This is a member function I wrote:
bool MyClass::eek:perator==(const MyClass &a_suaDateTime) const
{
return (m_oleDateTime == a_suaDateTime.DateTime()); //m_oleDateTime
an MFC class
}

I get this error message:
error C2662: 'DateTime' : cannot convert 'this' pointer from 'const
class CSuaDateTime' to 'class CSuaDateTime &'
Conversion loses qualifiers

Why???
Thanks!
 
V

Victor Bazarov

Hi,

This is a member function I wrote:
bool MyClass::eek:perator==(const MyClass &a_suaDateTime) const
{
return (m_oleDateTime == a_suaDateTime.DateTime()); //m_oleDateTime
an MFC class
}

I get this error message:
error C2662: 'DateTime' : cannot convert 'this' pointer from 'const
class CSuaDateTime' to 'class CSuaDateTime &'
Conversion loses qualifiers

Why???

Apparently, 'DateTime' is a non-const function. Don't call it, just
compare the values of 'm_oleDateTime' members:

return m_oleDateTime == a_suaDateTime.m_oleDateTime;

V
 
R

red floyd

Hi,

This is a member function I wrote:
bool MyClass::eek:perator==(const MyClass &a_suaDateTime) const
{
return (m_oleDateTime == a_suaDateTime.DateTime()); //m_oleDateTime
an MFC class
}

I get this error message:
error C2662: 'DateTime' : cannot convert 'this' pointer from 'const
class CSuaDateTime' to 'class CSuaDateTime &'
Conversion loses qualifiers

Why???
Thanks!

Can't be sure of the definition of your class, but my guess is that

MyClass::DateTime() is not defined as a const method.
 
D

dushkin

Hi Victor and Red!

You were both right! I forgot to set DateTime() as const method!

Thanks a lot!
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top