Solved

Undefined type on forward reference

Posted on 2001-08-31
13
293 Views
Last Modified: 2013-11-20
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
Comment
Question by:ealva
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 9

Expert Comment

by:Pacman
ID: 6443950
which code line causes this error ?
I guess it's not
> CClientSocket::CClientSocket(CSockControl *pSockControl)
0
 

Author Comment

by:ealva
ID: 6443972
It's the one with "FAILS!". :-)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6443983
>>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
 
LVL 9

Expert Comment

by:Pacman
ID: 6443996
>> It's the one with "FAILS!". :-)

Sorry, I must be blind !
In this case Dan's right.
0
 

Author Comment

by:ealva
ID: 6444027
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
 

Author Comment

by:ealva
ID: 6444041
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 6444056
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
 
LVL 9

Expert Comment

by:Pacman
ID: 6444193
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
 

Expert Comment

by:stkh_nz
ID: 6445079
"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
 

Expert Comment

by:stkh_nz
ID: 6445092
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 6445944
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
 

Author Comment

by:ealva
ID: 6449441
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
 

Expert Comment

by:stkh_nz
ID: 6449933
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 84
conditional code and condition difference 9 65
bigDiff challenge 17 75
Fibonacci challenge 11 84
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now