Solved

Undefined type on forward reference

Posted on 2001-08-31
13
298 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.

808 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