Programming Topics + Letters to the Editor + Overload Journal #5 - Sep 1994
Browse in : All > Topics > Programming
All > Journal Columns > LettersEditor
All > Journals > Overload > 05
Any of these categories - All of these categories

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: Letters

Author: Martin Moene

Date: 09 May 2012 00:00:00 +01:00 or Wed, 09 May 2012 00:00:00 +01:00

Summary: 

Body: 

Dear Mike,

Congratulations on the first four issues of Overload, I would like to add a couple of comments to your answers in the last two issues (in a spirit of .pedantry only). In Issue 3 P34 Q4 you appear to have overcomplicated the solution with conditional compilation!

Simply declare the const array as extern, declare the class using the const array name as the default argument and define the const array in the source file as for any initialised data:

hello.hpp:

extern const char name[];
void print( const char str[] = name );

hello.cpp:

#include "extconst.hpp"
#include <iostream.h)
const char name[] = {"Hello World"};
void print( const char str[] )
{
 cout << str;
}

void main()
{
 print();
}

In issue 4 p44 Q10 you say “… if polymorphic member function is called, only the base member function will be called”. I’m sure it was just a slip of the tongue but in fact it will be the constructors own version of the function that is called, whether it happens to be the base class or not. Interestingly, although the virtual calling mechanism is supposed to be turned off, the virtual method tables are still used to call virtual functions.

The way it works is that as each base object is constructed, the virtual method pointer is set to the table for that class, immediately prior to the body of the constructor being executed. This means that the method table will contain the addresses of the functions that would apply to an instance of the class of the constructor in use. This means that it isn’t possible to subvert this behaviour - even calling the functions via a base pointer in another function will only get the same method table. Interestingly it’s possible to call a pure virtual function this way without the compiler ever realising it - you’ll find out at run-time of course!

Adrian Fagg

Thank’s for the corrections and information.

Mike Toms.

Notes: Generated via JPG, Google OCR, pandoc markdown from scanned journal

More fields may be available via dynamicdata ..