James Kanze
9/10/2008 8:52:00 AM
On Sep 10, 12:09 am, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> Immortal_Ne...@hotmail.com wrote:
> > This Run() function is function pointer. It contains three
> > functions. How can you put const in Run() function? It
> > should guard against modifying Run()'s function pointer
> > array.
> So, you need the elements of the array to be const, right?
> You should tell your compiler so.
> > Do you know what do const before void mean? For example --
> > const void foo() {}.
> It doesn't mean much, I can tell you that.
And it's not really placed where it should be: const normally
follows what it modifies (although as you say, the idea of a
function which returns nothing, but doesn't allow you to modify
that nothing, is pretty useless).
> > class Obj
> > {
> > public:
> > Obj();
> > ~Obj();
> > static void (*Run[3])(void);
> static void (* const Run[3])();
You should have mentionned the basic principle here: const
follows what it to be constant. In this case, the pointers are
to be constant, so the const is inserted after the *. (The case
of arrays is a bit special, since you can't have a constant
array. The syntax doesn't allow it directly, and even with
typedef, at least in C, the rule is that if the const is applied
to the array, it is not the array that is const, but each of the
elements. But I don't think that this makes any difference in
practice.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34