dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Jun 26, 2000

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Initialization of Built-In Types

Question:
What does the declaration int i(0) ; mean? Does C++ have a type 'int' constructor? And why doesn't Visual C++ accept a char* p(0) ; declaration?

Answer:
This expression creates a variable of type int and initializes it to 0. You can achieve the same effect with the following statement:

int i=0;
Technically, built-in types don't really have a constructor. The compiler transforms the original expression to a simple initialization expression when the variable is of a built-in type. C++ allows you to use this syntax with built-in types for the sake of templates. Templates take an unspecified object as an argument. They can't tell in advance whether the variable is a built-in type or a class object. To enable them to treat that argument in a uniform fashion regardless of its type, C++ permits the use of this initialization form for built-in types.

The expression char* p(0) ; is valid and should be accepted by a standard-compliant compiler. However, Visual C++ has a bug.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date