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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:44:40+00:00 2026-05-16T10:44:40+00:00

I was wondering, why can’t there be a void data type that is not

  • 0

I was wondering, why can’t there be a void data type that is not a pointer?

Surely you could get past the whole determined size thing by having

void4
void8
void32

And then only being allowed to ‘cast’ a void data type to another class if its size is equal or under to the classes size.

Is there something that I’m missing, or does the C++ committee just consider it bad practise?

EDIT:

I haven’t explained myself very well, so I’ll give an example of its use:

 main()
{
    /* 

     Lets make a list of unknown elements

     std::string is 8 bytes, and float is 4
     bytes, so we'll reserve 8 byte sequences

     */

    vector<void8> elements;

    elements.push_back((void8) string("First string element"));

    elements.push_back((void8) float(5.76) );

    elements.push_back((void8) string("Third string element"));

    // Ect.

    cout << (string) elements[0];
    cout << (float) elements[1];
    cout << (string) elements[2];
    cout << (float) elements[2]; // Garbage


    void1 data;

    data = (void1) bool(1);
    data = (void1) unsigned int(80094); // Error, not enough size
}

Its named void because you don’t know what type it is currently storing, similar to the void pointer.

  • 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-16T10:44:40+00:00Added an answer on May 16, 2026 at 10:44 am

    In a strongly typed language, all data has a type, so there is no concept of “void” as a datatype. In C and C++, it’s meanings are either “no data” (as a return value), or “data whose type you don’t know” (as a pointer target).

    You are proposing an in-between state of “data whose type you don’t know but whose size you do”, presumably as an opaque version of a type you pass by value. Besides being rather a dangerous thing to do (since you have to manually update all the code using the opaque type when you change the size of the real type), this can already be done without adding weird extensions to the language, for example:

    struct void8 { char bytes[8]; };
    

    This could be used in conjunction with reinterpret_cast to pass POD types around as opaque lumps, in much the way you suggest. Using it with non-POD types is even more likely to invoke undefined behaviour than using void* to refer to non-POD types.

    It would be safer and more idiomatic to handle opaque types as pointers or references to named types that have been declared but not defined, or something like boost::any if you want value semantics. There’s rarely a need to use “void” as a placeholder type in C++.

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

Sidebar

Related Questions

I am wondering can I do a where clause that takes in a collection?
I know that you can use reflection in Java to get the name of
I am wondering how can I issue a HTTP Status code, that will cause
I was wondering how can I match two digits but which are not the
I was wondering how I can store variables server side that can be fired
was wondering how can I create a sub drop down box upon selecting a
I was wondering how can I track the current logged in user in a
I was wondering how can I control the image on the connect dialog? I
i'm wondering how can I compare in C language, a number I put on
I was wondering how can I do something similar to Facebook when a link

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.