Solved

Undefined type on forward reference

Posted on 2001-08-31
13
300 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 172
VBA "SendKeys" Syntax for Multiple Keystrokes 7 133
abstract class with all non abstract mentods 6 87
MaxSpan challenge 9 140
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ā€¦
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

739 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