Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:45:28+00:00 2026-06-13T09:45:28+00:00

I have strange behavior with typedef struct constructions in classes and functions. The difference

  • 0

I have strange behavior with typedef struct constructions in classes and functions. The difference is that in first case all definitions are performed during class definition. Another case — during function definition. Look at my code.

class C
{
public:
    //struct xStruct;
    typedef struct xStruct* xPtr;
    typedef struct xStruct {xPtr F;} xStructR;
    typedef struct { xPtr First; } xPtr_Type;
    void F(void **Var)
    {
        xPtr Ptr = 0;
        ((xPtr_Type*)Var)->First = Ptr->F; //errors
    }
};

void Fu()
{
    typedef struct qxStruct* qxPtr;
    typedef struct qxStruct {qxPtr qF;} qxStructR;
    typedef struct { qxPtr qFirst; } qxPtr_Type;
    qxPtr qPtr = 0;
    void **qVar = 0;
    ((qxPtr_Type*)qVar)->qFirst = qPtr->qF;
}

During compilation with MS compiler (cl.exe) i have two errors:

error C2027: use of undefined type 'xStruct'
error C2227: left of '->F' must point to class/struct/union

If i uncomment struct xStruct declaration my code works. But i can’t understand why the similar code works fine in Fu function without struct xStruct declaration? It seems that compiler has more strict algorithms of code analysing during class definition…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:45:29+00:00Added an answer on June 13, 2026 at 9:45 am

    I see one difference:

    In class C compiler treats first occurence of struct xStruct as from global namespace. The second is from class C namespace – that’s why the error during assignment.

    class C
    {
    public:
        //struct xStruct;
        typedef struct xStruct* xPtr; 
        //      ^^^^^^^^^^^^^^  forward declaration of global type ::xStruct
        typedef struct xStruct {xPtr F;} xStructR;
        //      ^^^^^^^^^^^^^^^^^^^^^^^^  definition of local type C::xStruct
        typedef struct { xPtr First; } xPtr_Type;
        //                    ^^^^^ pointer to ::xStruct not C::xStruct
        void F(void **Var)
        {
           xPtr Ptr = 0;
           //   ^^^ pointer to global incomplete type
           ((xPtr_Type*)Var)->First = Ptr->F; //errors
           //                         ^^^^^^ using of ::xStruct which is incomplete
        }
    

    In global function example both definitions are from global namespace, so no problem there.

    To prove it I extended your example – now it compiles without problems:

    class C
    {
    public:
        //struct xStruct;
        typedef struct xStruct* xPtr;
        typedef struct xStruct {xPtr F;} xStructR;
        typedef struct { xPtr First; } xPtr_Type;
        void F(void **Var);
    };
    
    struct xStruct {
      ::xStruct* F;    
    };
    void C::F(void **Var)
    {
        xPtr Ptr = 0;
        ((xPtr_Type*)Var)->First = Ptr->F; //no errors
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a horizontal animated menu that has a strange behavior because it works
I have a strange behavior in a tests where I want to test that
I have come across a strange behavior with Microsoft Code Contracts that I don't
I have some strange behavior occurring in an ASP.NET application that I am trying
I have faced some strange behavior in the R's all.equal function. Basically, I create
I have encountered a strange behavior of BindingSource. First I set it's DataSource in
I have a strange behavior for an application that I have implemented and that
I have discovered a strange behavior in postgres's crosstab function that I cannot explain,
I have realy strange behavior. I have this code (I remove unrelated code). $(function()
I have this strange behavior in my JSP page: I have two Integer variables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.