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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:40:56+00:00 2026-06-07T14:40:56+00:00

In my code i have int s, bool s, pointer s and so on,

  • 0

In my code i have ints, bools, pointers and so on, i also have some type defined by me with typedef, how can i manage the default value initialization like it happens in the objects with the contrunctor?

I want to be sure that

T var;

if untouched, is always equal to my default value and i like to do this without parsing each line of code anche changing the default value manually and without using a preprocessor macro.

is this possible?
for a new typedef is possible to define a default value?

  • 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-07T14:40:57+00:00Added an answer on June 7, 2026 at 2:40 pm

    In C++11, you could write T var{}; to get value initialization to the default value.

    In C++03, you could write a non-POD wrapper, whose default constructor will get called by T var;:

    template<class T>
    struct default_initializer{
      default_initializer() : value() {}
      default_initializer(T const& v) : value(v) {}
      T value;
    };
    
    // somewhere in code
    default_initializer<T> var; // calls default ctor and initializes 'value'
                                // to its default value
    

    This will allow you to safely default initialize even primitive , POD and aggregate types, which are normally left uninitialized by the T var; declaration.

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

Sidebar

Related Questions

If I have code such as class CString { int GetLength(); }; bool smaller(CString
I have the following code: int width = 10; int height = 7; bool[,]
I have a Func in my code that's declared like this: Func<string, int, bool>
When you have code: for(int i = 0; i<N; i++) { array[i] += N
Let's say I have int a() { /* Tons of code ....*/ return someInt;
I have next code: int main() { OwnSelect(23, FD_READ | FD_WRITE); // <---- Several
I have this code: int se = (int) settings.GruppoSegreteria; var acc = db.USR_Accounts.Where( p
I have code that is similar to this: public xyz (int? a) { if
I have code similar to this: public List<string> Expected = new List<string>(); public int
I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor

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.