Solved

Undefined type on forward reference

Posted on 2001-08-31
13
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

628 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