"Default construction" of built-in types?

From: DaKoadMunky (dakoadmunky_at_aol.com)
Date: 05/29/04


Date: 29 May 2004 03:09:46 GMT

I recently came across some code in a template that default constructed an
object of type T to pass to another function...

SomeFunction(T());

The code that instantiates that template specifies T as an int.

Proper program behavior relies on that "default constructed" int being zero.

That lead me to the following example...

int main()
{
  int i; //Uninitialized! Expected for automatic of built-in type

  int j = int(); //Initialized to zero! Not sure what to expect

  return 0;
}

Is such "default construction" of built-in types standard C++?

char() == 0
int()==0

etc...

Thanks



Relevant Pages

  • Simple script annimation problem usig swing
    ... To change this template, ... public void destroy{ ... public state cstate; ... public static int respawn = 20; ...
    (comp.lang.java.programmer)
  • Re: Simple script annimation problem usig swing
    ... To change this template, ... public void destroy{ ... public state cstate; ... public static int respawn = 20; ...
    (comp.lang.java.programmer)
  • implementation details
    ... template class ) ... Retrieve then I'd like to implement some sort of overrun check. ... BUFFER(); ... unsigned int retrieve_count; ...
    (comp.lang.cpp)
  • Re: Replacing merge fields in headers/footers
    ... database, and a newly populated document can be requested at any time. ... to my way of thinking is to have a merge template ... I'm using exactly the same code to populate the fields in the ... >> private FileStream PopulateTemplateDocument(int theFileID, ...
    (microsoft.public.word.vba.general)
  • friend ostream& operator<< (ostream&, Array<T>&);
    ... Array(int itsSize = DefaultSize); ... int GetSize() const ... make sure the function template has already been declared and add after ... // implement the Constructor ...
    (alt.comp.lang.learn.c-cpp)