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 3407812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:47:50+00:00 2026-05-18T05:47:50+00:00

Can any one explain class X x; what actually it mean …in the program…Please

  • 0

Can any one explain “class X x;” what actually it mean …in the program…Please give me some example also?
Ex:

#include <iostream>
using namespace std;

class X {
    public:
        X() {}
};

class Y {
    public:
        Y() {}
};

int main()
 {
    class X x; //what is this? explain it
    class Y y; //what is this? explain it
    class Z z; //what is this? explain it    //error
    return 0;
  }

Edited: May i know the exact difference between “Class Z z” and “Z z”.Because While
compiling this program in 2 ways

  class Z Z;   //here iam getting as Error: error: incomplete type is not allowed
  Z z; //error: identifier "Z" is undefined

Since iam asking the exact difference.

  • 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-05-18T05:47:50+00:00Added an answer on May 18, 2026 at 5:47 am

    AFAIK

    class X x;
    

    is equivalent to

    X x;
    

    (EDIT: for those nitpickers: at least, in your case, when X is a previously defined class and there is no other variable named X in the same scope).

    In plain-old C, whenever you define a struct without a typedef, you have explicitly use the struct keyword when creating variables. In C++, one can omit the struct keyword, but you also can write struct X x; if you prefer that. And since the only difference between class and struct in C++ is the default visibility, one can conclude that it is also legal to write class X x;

    Answer to your edit:

     class Z;
    

    is a forward declaration (often used in header files where you don’t want to #include "Z.hpp"). This is also called an incomplete type declaration. It allows pointers to Z to be declared, for example

     class Z *z;
    

    is legal code, even when the compiler has not seen any class body declaration of Z. What is not allowed is to create an instance of z like class Z z; as long as Z is incomplete from the compiler’s view.

    The code Z z;, however cannot be interpreted as a forward declaration by the compiler (not even as a disallowed forward declaration). It just shows up as “Z is undefined”.

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

Sidebar

Related Questions

Can any one explain why the output of this code is only 'hello' and
can any one explain While we are importing a package we can use its
Greetings everyone. Can any one has a working example for the CoreTelephony framework? I
Can anyone explain the difference between the types mentioned above and some sample usage
Can anyone help me explain how TimeProvider.Current can become null in the following class?
In my application i have some view controllers and one objective c class ,how
Can someone explain what the different between these two instantiations of the ArrayList class?
Can anyone explain what this mod_rewrite rule is doing? I'm trying to comment the
Can anyone explain what advantages there are to using a tool like MSBuild (or
Can anyone explain why following code won't compile? At least on g++ 4.2.4. And

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.