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

  • Home
  • SEARCH
  • 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 8282677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:27:19+00:00 2026-06-08T10:27:19+00:00

Like Java and C#, can I create object of a class within the same

  • 0

Like Java and C#, can I create object of a class within the same class?

/* State.h */
class State{
  private:
    /*...*/
    State PrevState;
};

Error:

field 'PrevState' has incomplete type
  • 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-08T10:27:21+00:00Added an answer on June 8, 2026 at 10:27 am

    You cannot do this as written. When you declare a variable as some type directly in a class (Type variablename) then the memory for the variable’s allocation becomes part of its parent type’s allocation. Knowing this, it becomes clear why you can’t do this: the allocation would expand recursively — PrevState would need to allocate space for it’s PrevState member, and so on forever. Further, even if one could allocate an infinite amount of memory this way, the constructor calls would recurse infinitely.

    You can, however, define a variable that is a reference or pointer to the containing type, either State & or State * (or some smart pointer type), since these types are of a fixed size (references are usually pointer-sized, and pointers will be either 4 or 8 bytes, depending on your architecture).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

like in java I have: Class.getSuperClass().getDeclaredFields() how I can know and set private field
When we create interface methods, can't we do something like in java : void
In Java you can do something like: byte[] code = ReadFromClassFile(SomethingSomething.class); SendAcrossNetwork(code); And on
Possible Duplicate: declare property as object? in java you can create an object directly
So I come from a background in Java where you can create a class
In C# and Java a byte array can be created like this byte[] b
How can we draw the shapes in Java like we do in paint? For
OK - I know I can run my java process like this : java
How can I convert from bytes to float in php? Like in Java int
With generics on languages like C# or Java, you can have a factory that

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.