Why moving a function from protected to public area in class causes error C2556

A

Angus

Why moving a function from protected to public area in class causes
error C2556 - overloaded function differs only by return type

I have a protected function called GetState like this:

enum EState GetState(void) const throw();

If I move this function from protected: to public: I get this compile
error:

xbasicsocket.cpp(247) : error C2556: 'enum CXBasicSocket::EState
__thiscall CXBasicSocket::GetState(void) const' : overloaded function
differs only by return type from 'enum EState __thiscall
CXBasicSocket::GetState(void) const'
\xbasicsocket.h(154) : see declaration of 'GetState'
\xbasicsocket.cpp(247) : error C2371: 'GetState' : redefinition;
different basic types
\xbasicsocket.h(154) : see declaration of 'GetState'


In the cpp file it is declared like this:

enum CXBasicSocket::EState CXBasicSocket::GetState(
) const throw()
{
return m_eState;
}

Why am I geting this problem? How do I resolved?
 
J

Jim Langston

Angus said:
Why moving a function from protected to public area in class causes
error C2556 - overloaded function differs only by return type

I have a protected function called GetState like this:

enum EState GetState(void) const throw();

If I move this function from protected: to public: I get this compile
error:

xbasicsocket.cpp(247) : error C2556: 'enum CXBasicSocket::EState
__thiscall CXBasicSocket::GetState(void) const' : overloaded function
differs only by return type from 'enum EState __thiscall
CXBasicSocket::GetState(void) const'
\xbasicsocket.h(154) : see declaration of 'GetState'
\xbasicsocket.cpp(247) : error C2371: 'GetState' : redefinition;
different basic types
\xbasicsocket.h(154) : see declaration of 'GetState'


In the cpp file it is declared like this:

enum CXBasicSocket::EState CXBasicSocket::GetState(
) const throw()
{
return m_eState;
}

Why am I geting this problem? How do I resolved?

Most likely, it isn't recognizing EState and CXBasicSocket::EState as being
the same. In the prototype change it to CXBasicSocket::EState as the return
value and see if the error goesa away.
 

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

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top