• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Undefined type on forward reference

I have an ATL control project:

---
SockControl.h:

class ATL_NO_VTABLE CSockControl :
  ...
{
public:
    CSockControl()
    {
        m_pSocket = new CClientSocket(this);
    }
    void OnReceive()
    {
        Fire_DataArrival(120);
    }
    ...
}

---
ClientSocket.h:

class CSockControl;
class CClientSocket : public CAsyncSocket
{
    CClientSocket(CSockControl *pSockControl);
    virtual ~CClientSocket();

    virtual void OnReceive(int nErrorCode);
}

---
ClientSocket.cpp:

CClientSocket::CClientSocket(CSockControl *pSockControl)
{
    m_pSockControl = pSockControl;
}

void CClientSocket::OnReceive(int nErrorCode)
{
    m_pSockControl->OnReceive();    // FAILS!
    ....
}

---

I get this: "ClientSocket.cpp : error C2027: use of undefined type 'CSockControl'"

I know I set my forward references correctly.  What's happening here?

0
ealva
Asked:
ealva
  • 4
  • 3
  • 3
  • +1
1 Solution
 
PacmanCommented:
which code line causes this error ?
I guess it's not
> CClientSocket::CClientSocket(CSockControl *pSockControl)
0
 
ealvaAuthor Commented:
It's the one with "FAILS!". :-)
0
 
DanRollinsCommented:
>>m_pSockControl->OnReceive();    // FAILS!

I think it is this line causein the error.  THis will happen because you have used a forward referemce for the variable m_pSocketControl.  ALl the compiler knows is that it si a pointer, not that it has a member named OnRecieve().

Solution...

#include "SocketControl.h"

in ClientSocket.cpp:

-- Dan
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
PacmanCommented:
>> It's the one with "FAILS!". :-)

Sorry, I must be blind !
In this case Dan's right.
0
 
ealvaAuthor Commented:
Dan, did that already, just blows up, splashing "undeclared identifiers" everywhere.  I'm working on an ATL project and SockControl is the implementation class.

Maybe I can just send the partially-done source to you?
0
 
ealvaAuthor Commented:
Dan, did that already, just blows up, splashing "undeclared identifiers" everywhere.  I'm working on an ATL project and SockControl is the implementation class.

Maybe I can just send the partially-done source to you?
0
 
DanRollinsCommented:
I'd like to help, but these are the kinds of problems i *really* hate and anyway, they are solvable only by someone who in intimate with the code.  Start from this:

You *must* be able to include that header in that file.  Maybe you can strip down the #includes that *it* includes to minimize the problem.

Otherwise, you just need to look at each compiler error and figure out why it occured.

>>splashing "undeclared identifiers" everywhere

I don't think there is any alternative to simply figuring out why each of those indentifiers in undeclared.  Then making certain that they get declared.

-- Dan
0
 
PacmanCommented:
if you get undeclared identifiers then you've to locate the declarations and include all the neccesary header files. Do this step by step till all identifiers are declared. If you move in circle then redesign your concept of placing things in headers.

Good Luck
0
 
stkh_nzCommented:
"SockControl.h" should be included AFTER "ClientSocket.h".
I've pasted your code into a new MFC project, deleted all the stuff that was not related to this project (comments, ...'s, ATL_NO_VTABLE, CAsyncSocket base class"),
and added the pointer member functions. If you put
#include "ClientSocket.h"
#include "SockControl.h"
in the beginning of both ClientSocket.cpp and SockControl.cpp it compiles without problems. If you omit the #include "SockControl.h" from ClientSocket.cpp you get your error at the indicated line. If you put #include "SockControl.h" before #include "ClientSocket.h" you get undeclared's

hth
Steen.
0
 
stkh_nzCommented:
Oops! - typo in my previous post. I added the pointer member variables, not pointer member functions. Sorry.

cheers
Steen.

P.S. I'm new to EE - should my previous post be regarded as answer or comment? I mean, it's an answer but it's an elaboration of somebody else's comment. I don't really care about points, so if I've done something wrong please accept my apologies.
0
 
DanRollinsCommented:
hi stkh_nz,
The experts in this section all agree --

post comments, not answers

There are several reasons for this, but in this case it is obvious.  There is no way that you have all of the header files that ealva is using, so there is no way to duplicate the problem and thus no way to provide the "definitive and only" answer.

In the future, please post comments like everybody else.  If the comment solves the asker's problem, then he will click [Accept Comment as Answer] and you will get credit.  Thanks!

-- Dan
0
 
ealvaAuthor Commented:
I have figured it out!  Since this is an ATL project, I also need to include the header file generated from the .idl (which is another file SockCtrl.h from SockCtrl.idl).  In this case, DanRollins's answer is the correct one.

I have provided only contextual info in my question (ATL), so my apologies if I haven't stated everything correctly.

Thanks for all the help guys! :-)
0
 
stkh_nzCommented:
Hi Dan,

thanks for setting me straight. I'll post comments in the future. Again, please accept my apologies. I didn't mean to offend anyone.

cheers
Steen.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now