Solved

"differs in levels of indirection from unknown-type"

Posted on 2004-10-04
8
629 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
Comment Utility
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
Comment Utility
Compiles fine here. VC 6 and 7.1.

What line does the error correspond to?
0
 

Author Comment

by:jd9288
Comment Utility
>>jkr
same thing...

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

0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Is there any other code before that line?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:jd9288
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

762 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

11 Experts available now in Live!

Get 1:1 Help Now