Solved

"differs in levels of indirection from unknown-type"

Posted on 2004-10-04
8
632 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 86

Expert Comment

by:jkr
ID: 12220790
Is there any other code before that line?
0
 

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

831 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