| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
March 22, 2005 Initializing global arrays in modules via this()? | ||||
|---|---|---|---|---|
| ||||
Initializing global arrays in modules (i.e. outside functions), someone
mentioned this() as a solution:
<code>
module aepar_global;
const int MLdataNo = 13;
int[] metaData;
// Initializing Arrays (before main() is called)
this()
{
metaData.length = MLdataNo;
// or metaData.length = metaData.length + MLdataNo;
}
</code>
Alas this yields an error:
// aepar_global.d(115): constructor aepar_global.this constructors only are for
class definitions
And since
int[MLdataNo] metaData;
does not work either, I am a bit at loss what to do?
AEon
| ||||
March 22, 2005 Re: Initializing global arrays in modules via this()? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to AEon | Its a simple mistake: you need to make the module constructor static. Ie:
# static this() {
# metaData.length = MLdataNo;
# }
The error message could be a little more helpful, I suppose. Maybe by suggesting that what you seem to want is a 'static this()'.
-- Chris Sauls
AEon wrote:
> // Initializing Arrays (before main() is called)
> this()
> {
> metaData.length = MLdataNo;
> // or metaData.length = metaData.length + MLdataNo;
> }
> </code>
>
> Alas this yields an error:
>
> // aepar_global.d(115): constructor aepar_global.this constructors only are for
> class definitions
| |||
March 22, 2005 Re: Initializing global arrays in modules via this()? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Chris Sauls | Chris Sauls says...
>Its a simple mistake: you need to make the module constructor static. Ie:
>
># static this() {
># metaData.length = MLdataNo;
># }
>
>The error message could be a little more helpful, I suppose. Maybe by suggesting that what you seem to want is a 'static this()'.
Ah thanx... alas since it is not possible to search newsgroups, I was not able to find the initial post, that not doubt was correct.
AEon
| |||
March 22, 2005 Re: Initializing global arrays in modules via this()? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to AEon | In article <d1pqbb$aqt$1@digitaldaemon.com>, AEon says... > .. >Ah thanx... alas since it is not possible to search newsgroups, ... To a certain extent, you can search the newsgroups: http://www.digitalmars.com/advancedsearch.html See also: http://www.prowiki.org/wiki4d/wiki.cgi?NewsDmD#NewsreadervsWebInterface jcc7 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply