Il est permis de donner à une variable le même nom qu'une classe ?
Malheureusement oui. Encore une connerie issue de la compatibilité avec le C.
En fait, en C, on écrirait :
int main() { struct A A; }
James Kanze
On Jan 16, 10:18 pm, Fabien LE LEZ wrote:
On Wed, 16 Jan 2008 21:15:21 +0100, David Côme :
Il est permis de donner à une variable le même nom qu'une classe ?
Malheureusement oui. Encore une connerie issue de la compatibilité avec le C.
En fait, en C, on écrirait :
int main() { struct A A; }
Il y a ça aussi, mais ça n'entre pas en jeu dans son cas, qui est beaucoup plus simple :
struct A{} ;
int main() { A A ; }
Ici, tout ce qui se passe, c'est que la portée de la variable A ne commence qu'une fois le compilateur l'a vue -- formellement, à la fin du « declarator » complet, mais avant l'initialisateur (s'il y en a). Même quelque chose du genre :
int const A = 10 ;
int main() { int A[ A ] ; }
est légal, puisque l'A dans main n'est pas encore visible dans la spécification de la dimension (qui fait partie du declarator).
Ce auquel tu penses, c'est une autre règle, en effet un hack pour des raisons de compatibilité C. C-à-d que 1) on a droit de réutiliser un nom (une fois seulement) comme nom de classe ou nom d'enum (n'oublie pas ici que les mots clés class, struct et union tous déclarent un nom de classe), 2) s'il y a ambiguïté entre un nom de classe et d'autres choses, on ôte le nom de la classe de considération, et 3) dans un « elaborated type specifier » (c-à-d quelque chose qui commence par class, struct ou union), on ne prend pas en compte les noms qui ne sont pas des noms de classe. Ce qui permet des choses du genre :
int main() { int A ; struct A { int i ;} ; struct A a1 = { A } ; }
Que la définition de la structure A se trouve dans main(), ou avant, ne change rien ici. En revanche, la struct A ne serait trouvé que si le symbole A suit le mot clé struct, class ou union -- dans tous les autres cas, on trouve la variable.
-- James Kanze (GABI Software) email: 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
On Jan 16, 10:18 pm, Fabien LE LEZ <grams...@gramster.com> wrote:
On Wed, 16 Jan 2008 21:15:21 +0100, David Côme <davidc...@wanadoo.fr>:
Il est permis de donner à une variable le même nom qu'une classe ?
Malheureusement oui. Encore une connerie issue de la compatibilité
avec le C.
En fait, en C, on écrirait :
int main()
{
struct A A;
}
Il y a ça aussi, mais ça n'entre pas en jeu dans son cas, qui
est beaucoup plus simple :
struct A{} ;
int main()
{
A A ;
}
Ici, tout ce qui se passe, c'est que la portée de la variable A
ne commence qu'une fois le compilateur l'a vue -- formellement,
à la fin du « declarator » complet, mais avant
l'initialisateur (s'il y en a). Même quelque chose du genre :
int const A = 10 ;
int main()
{
int A[ A ] ;
}
est légal, puisque l'A dans main n'est pas encore visible dans
la spécification de la dimension (qui fait partie du
declarator).
Ce auquel tu penses, c'est une autre règle, en effet un hack
pour des raisons de compatibilité C. C-à-d que 1) on a droit de
réutiliser un nom (une fois seulement) comme nom de classe ou
nom d'enum (n'oublie pas ici que les mots clés class, struct et
union tous déclarent un nom de classe), 2) s'il y a ambiguïté
entre un nom de classe et d'autres choses, on ôte le nom de la
classe de considération, et 3) dans un « elaborated type
specifier » (c-à-d quelque chose qui commence par class, struct
ou union), on ne prend pas en compte les noms qui ne sont pas
des noms de classe. Ce qui permet des choses du genre :
int main()
{
int A ;
struct A { int i ;} ;
struct A a1 = { A } ;
}
Que la définition de la structure A se trouve dans main(), ou
avant, ne change rien ici. En revanche, la struct A ne serait
trouvé que si le symbole A suit le mot clé struct, class ou
union -- dans tous les autres cas, on trouve la variable.
--
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
Il est permis de donner à une variable le même nom qu'une classe ?
Malheureusement oui. Encore une connerie issue de la compatibilité avec le C.
En fait, en C, on écrirait :
int main() { struct A A; }
Il y a ça aussi, mais ça n'entre pas en jeu dans son cas, qui est beaucoup plus simple :
struct A{} ;
int main() { A A ; }
Ici, tout ce qui se passe, c'est que la portée de la variable A ne commence qu'une fois le compilateur l'a vue -- formellement, à la fin du « declarator » complet, mais avant l'initialisateur (s'il y en a). Même quelque chose du genre :
int const A = 10 ;
int main() { int A[ A ] ; }
est légal, puisque l'A dans main n'est pas encore visible dans la spécification de la dimension (qui fait partie du declarator).
Ce auquel tu penses, c'est une autre règle, en effet un hack pour des raisons de compatibilité C. C-à-d que 1) on a droit de réutiliser un nom (une fois seulement) comme nom de classe ou nom d'enum (n'oublie pas ici que les mots clés class, struct et union tous déclarent un nom de classe), 2) s'il y a ambiguïté entre un nom de classe et d'autres choses, on ôte le nom de la classe de considération, et 3) dans un « elaborated type specifier » (c-à-d quelque chose qui commence par class, struct ou union), on ne prend pas en compte les noms qui ne sont pas des noms de classe. Ce qui permet des choses du genre :
int main() { int A ; struct A { int i ;} ; struct A a1 = { A } ; }
Que la définition de la structure A se trouve dans main(), ou avant, ne change rien ici. En revanche, la struct A ne serait trouvé que si le symbole A suit le mot clé struct, class ou union -- dans tous les autres cas, on trouve la variable.
-- James Kanze (GABI Software) email: 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
Mickaël Wolff
It may have been the warning given by Attorney General Pauncefote, it may have been something else. Whatever it was, the Commission informs us: "The Ordinance 10 of 1867 received its final sanction when the conclusion arrived at by the Colonial Government was before the home authorities, showing that in the event of the ordinance becoming law, _revenue would be derived_ from the tainted source of prostitution among the Chinese." (The italics are the authors').
Ordinance 10, 1867 now came into operation, with the following additional powers in the hands of the "Protector" of Chinese, the Registrar General:
1st, Not only were keepers of unregistered houses to be fined or sent to prison, but the women--"held in practical slavery for the purposes of prostitution"--when found in unregistered houses were also subject to fine and imprisonment.
2nd, The Registrar-General, otherwise the "Protector" of Chinese, could break into any house suspected of being a brothel, and arrest the keeper thereof without warrant. And he could authorize his underlings to do the same.
3rd, The Registrar General could exercise both judicial and executive powers in the prosecution of the duties of his office.
4th, All outdoor prostitutes could be arrested without warrant, fined and imprisoned.
The new law possessed one virtue over the old. It frankly, and more honestly, employed the word "licensed," where the old law said "registered," brothels.
The report of the Commission says:
"Although the new Ordinance conferred such extensive and unusual powers on the Registrar General and Superintendent of Police
It may have been
the warning given by Attorney General Pauncefote, it may have been
something else. Whatever it was, the Commission informs us: "The
Ordinance 10 of 1867 received its final sanction when the conclusion
arrived at by the Colonial Government was before the home authorities,
showing that in the event of the ordinance becoming law, _revenue
would be derived_ from the tainted source of prostitution among the
Chinese." (The italics are the authors').
Ordinance 10, 1867 now came into operation, with the following
additional powers in the hands of the "Protector" of Chinese, the
Registrar General:
1st, Not only were keepers of unregistered houses to be fined or
sent to prison, but the women--"held in practical slavery for the
purposes of prostitution"--when found in unregistered houses were
also subject to fine and imprisonment.
2nd, The Registrar-General, otherwise the "Protector" of Chinese,
could break into any house suspected of being a brothel, and
arrest the keeper thereof without warrant. And he could authorize
his underlings to do the same.
3rd, The Registrar General could exercise both judicial and
executive powers in the prosecution of the duties of his office.
4th, All outdoor prostitutes could be arrested without warrant,
fined and imprisoned.
The new law possessed one virtue over the old. It frankly, and
more honestly, employed the word "licensed," where the old law
said "registered," brothels.
The report of the Commission says:
"Although the new Ordinance conferred such extensive and unusual
powers on the Registrar General and Superintendent of Police
It may have been the warning given by Attorney General Pauncefote, it may have been something else. Whatever it was, the Commission informs us: "The Ordinance 10 of 1867 received its final sanction when the conclusion arrived at by the Colonial Government was before the home authorities, showing that in the event of the ordinance becoming law, _revenue would be derived_ from the tainted source of prostitution among the Chinese." (The italics are the authors').
Ordinance 10, 1867 now came into operation, with the following additional powers in the hands of the "Protector" of Chinese, the Registrar General:
1st, Not only were keepers of unregistered houses to be fined or sent to prison, but the women--"held in practical slavery for the purposes of prostitution"--when found in unregistered houses were also subject to fine and imprisonment.
2nd, The Registrar-General, otherwise the "Protector" of Chinese, could break into any house suspected of being a brothel, and arrest the keeper thereof without warrant. And he could authorize his underlings to do the same.
3rd, The Registrar General could exercise both judicial and executive powers in the prosecution of the duties of his office.
4th, All outdoor prostitutes could be arrested without warrant, fined and imprisoned.
The new law possessed one virtue over the old. It frankly, and more honestly, employed the word "licensed," where the old law said "registered," brothels.
The report of the Commission says:
"Although the new Ordinance conferred such extensive and unusual powers on the Registrar General and Superintendent of Police