Journal Articles

CVu Journal Vol 11, #4 - Jun 1999
Browse in : All > Journals > CVu > 114 (20)

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.

Title: An Apology

Author: Administrator

Date: 03 June 1999 13:15:31 +01:00 or Thu, 03 June 1999 13:15:31 +01:00

Summary: 

Body: 

Last issue I managed to provide some code that should not compile on any compliant system even though it would be reasonable for it to work. Please accept my apologies for any inconvenience.

First let me consider a little code that does work:

void fn(){
  char message[100] = "";
  // do something
}

The array of char called message is declared with an initialiser. The result in this case is to zero all the elements of the array. The rule is simple, once you start initialising an array it is all initialised (with default constructors for the part that has not been explicitly initialised). Note that though I am thinking of message as a string, it is an array of char. The declaration is equivalent to:

  char message[100] = {'\0'};

Now there is at least one place in C++ where you are not permitted to use an initialiser for an array, that is in a constructor initialiser list.

You are not allowed to initialise an array of char in a constructor. It will have to be done in the body of the constructor.

The constructor I provide for student on page 39 of C Vu 11.3 will not work. To my mind this is just one more reason for using the C++ string type rather than the C array of char.

I must confess that I am not sure why C++ does not allow initialisation of arrays in ctors. The efficiency aspects are exactly the same as those in C (do not initialise at all and assign the ones you want versus initialise everything). The problem is that C++ requires you to hand code complete initialisation of any array that is a member of a user defined type. This seems an unnecessary burden.

Notes: 

More fields may be available via dynamicdata ..