Solved

"differs in levels of indirection from unknown-type"

Posted on 2004-10-04
8
630 Views
Last Modified: 2012-06-27
I declare a struct in PUB.h like so:

struct GLOBAL_STRUCT_G
{
      GLOBAL_STRUCT_G()
      {
            hInst                        = NULL;
            ThreadCount         = 0;
            MaxThreads                  = 200;
            hMainDlg                  = NULL;
            pMainFrame                  = NULL;
            pLeftView                  = NULL;
            pDoc                        = NULL;
            pDB                              = NULL;
      }

      HINSTANCE            hInst;
      TCHAR                  LocalComputerName[ MAX_PATH ];
      long                  ThreadCount;
      long                  MaxThreads;
      HWND                  hMainDlg;
      CMainFrame *      pMainFrame;
      CLeftView *            pLeftView;
      C_pr_temp_Doc *      pDoc;
      CDBAccess *            pDB;
};
typedef GLOBAL_STRUCT_G *stGLOBAL_STRUCT_G;

Then in MainFrm.cpp:

#include "PUB.h"

stGLOBAL_STRUCT_G p_G;

It gives me the error : error C2040: 'p_G' : 'stGLOBAL_STRUCT_G' differs in levels of indirection from ''unknown-type''
and I can't figure it out, for the life of me...
0
Comment
Question by:jd9288
  • 3
  • 3
  • 2
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 12220601
This is odd. Try

typedef struct
{
    GLOBAL_STRUCT_G()
    {
         hInst                    = NULL;
         ThreadCount         = 0;
         MaxThreads               = 200;
         hMainDlg               = NULL;
         pMainFrame               = NULL;
         pLeftView               = NULL;
         pDoc                    = NULL;
         pDB                         = NULL;
    }

    HINSTANCE          hInst;
    TCHAR               LocalComputerName[ MAX_PATH ];
    long               ThreadCount;
    long               MaxThreads;
    HWND               hMainDlg;
    CMainFrame *     pMainFrame;
    CLeftView *          pLeftView;
    C_pr_temp_Doc *     pDoc;
    CDBAccess *          pDB;

} GLOBAL_STRUCT_G, *stGLOBAL_STRUCT_G;

instead...
0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 250 total points
ID: 12220634
Compiles fine here. VC 6 and 7.1.

What line does the error correspond to?
0
 

Author Comment

by:jd9288
ID: 12220707
>>jkr
same thing...

>>What line does the error correspond to?
stGLOBAL_STRUCT_G p_G;

0
 
LVL 86

Expert Comment

by:jkr
ID: 12220790
Is there any other code before that line?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jd9288
ID: 12220892
No. Here's all of it up to that line:

// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "PUB.h"

#include "_pr_temp_View.h"
#include "EnumerateShares.h"
#include "EnumerateComputers.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

stGLOBAL_STRUCT_G p_G;
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 12220941
Is there any chance that there's a problem with the header files? What happens if you use

#include "stdafx.h"
#include "PUB.h"

stGLOBAL_STRUCT_G p_G;

?

BTW, does

GLOBAL_STRUCT_G* p_G;

work at all?



0
 
LVL 17

Expert Comment

by:rstaveley
ID: 12220951
It's probably worth checking that you've got all your braces closed and/or completed structures with semi-colons in:

#include "EnumerateComputers.h"
0
 

Author Comment

by:jd9288
ID: 12226064
>> Is there any chance that there's a problem with the header files?
The compiler error is quite misleading, actually...
Took me a while, but the global struct var is referenced in the included files
before it's defined, so all I had to do was put the struct's declaration first:

#include "stdafx.h"
#include "PUB.h"

#include "_pr_temp_View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

stGLOBAL_STRUCT_G p_G;

#include "EnumerateShares.h"
#include "EnumerateComputers.h"


Thank you very much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

919 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

21 Experts available now in Live!

Get 1:1 Help Now