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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:07:23+00:00 2026-06-15T07:07:23+00:00

Why am I getting an error when I try this in Visual C++? struct

  • 0

Why am I getting an error when I try this in Visual C++?

struct S { };
typedef S *S;

Doesn’t C++ let you typedef a name that was previously only declared as a class or struct?
Or am I misunderstanding what’s going on?

  • 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-15T07:07:24+00:00Added an answer on June 15, 2026 at 7:07 am

    C++ does allow you to typedef an existing class name, but only in a very restricted way. Once you declared your struct S you can do

    typedef struct S S;
    

    but you cannot do

    typedef struct S *S; // ERROR
    

    or

    typedef int S; // ERROR
    

    In the first case the fact that you are redefining S as a pointer is what breaks it.

    The language specification says in 7.1.3/2

    In a given non-class scope, a typedef specifier can be used to
    redefine the name of any type declared in that scope to refer to the
    type to which it already refers.

    “Already refers” is the key part. In simple words, you can redefine a class name to stand for the same class type, but not for a pointer to the class type or anything else.


    The aforementioned part of C++ standard is also what allows you to write repetitive typedefs like

    typedef int T;
    typedef int T;
    typedef int T;
    

    which would be illegal in C.

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

Sidebar

Related Questions

Im getting an error every time I try to debug this with Visual C++
Getting this error when try to compile a .net 1.1 website: Visual Studio .NET
I keep getting this error when i try to access forms that calls WCF
Ok... changing the question here... I'm getting an error when I try this: SELECT
Getting this error when try to add an item to my repositories/context: Collection has
Okay, I'm getting this error when I try to execute this procedure. The thing
I am getting this error when I try to deploy my Web API project
I'm getting this error when I try run DB:Rake : ** Invoke db:migrate (first_time)
I keep getting this error when I try to commit a group of executed
I am getting this error when I try to build for the device: Code

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.