(gelöst)[C++]2D-Array automatischer Größe geht nicht

Programmiersprachen, APIs, Bibliotheken, Open Source Engines, Debugging, Quellcode Fehler und alles was mit praktischer Programmierung zu tun hat.
Antworten
Benutzeravatar
Krishty
Establishment
Beiträge: 8267
Registriert: 26.02.2009, 11:18
Benutzertext: state is the enemy
Kontaktdaten:

(gelöst)[C++]2D-Array automatischer Größe geht nicht

Beitrag von Krishty »

Hi,

Ist es normal, dass dieser Code nicht funktioniert?

Code: Alles auswählen

int Test[][] = {
    { 0, 1, 2 },
    { 3, 4, 5 }
};
Mit int Test[][3] geht es, aber ich möchte, dass der Compiler die Größe automatisch bestimmt … mir ist gerade unklar, warum er das nicht hinkriegt. (VCpp 2010)

Gruß, Ky
Zuletzt geändert von Krishty am 26.01.2010, 20:32, insgesamt 1-mal geändert.
seziert Ace Combat, Driver, und S.T.A.L.K.E.R.   —   rendert Sterne
Arne
Beiträge: 6
Registriert: 28.02.2004, 15:12

Re: [C++]2D-Array automatischer Größe geht nicht

Beitrag von Arne »

Mir ist diese Problem auch bekannt. Eine einleuchtende Erklärung ist mir allerdings auch noch nicht untergekommen.
Ich kann dir als nicht helfen - nur den Frust mit dir teilen ;)

Gruß, Arne
Benutzeravatar
Aramis
Moderator
Beiträge: 1458
Registriert: 25.02.2009, 19:50
Echter Name: Alexander Gessler
Wohnort: 2016
Kontaktdaten:

Re: [C++]2D-Array automatischer Größe geht nicht

Beitrag von Aramis »

'Problem' ist wohl das falsche Wort ... :-)
C++-Standard hat geschrieben: D1 [ constant-expression opt ]
When several “array of” specifications are adjacent, a multidimensional array is created; the constant expressions that
specify the bounds of the arrays can be omitted only for the first member of the sequence
. [ Note: this elision is useful
for function parameters of array types, and when the array is external and the definition, which allocates storage, is
given elsewhere. —end note ] The first constant-expression can also be omitted when the declarator is followed by an
initializer (8.5). In this case the bound is calculated from the number of initial elements (say, N) supplied (8.5.1), and
the type of the identifier of D is “array of N T.”
Benutzeravatar
Krishty
Establishment
Beiträge: 8267
Registriert: 26.02.2009, 11:18
Benutzertext: state is the enemy
Kontaktdaten:

Re: [C++]2D-Array automatischer Größe geht nicht

Beitrag von Krishty »

Aramis hat geschrieben:'Problem' ist wohl das falsche Wort ... :-)
Nagut, nennen wir es aus bestimmten Blickwinkeln inkonsistent. Der Auszug hat es aber nun geklärt … schade drum, aber traurige Gewissheit ist besser als garkeine … danke dafür.
seziert Ace Combat, Driver, und S.T.A.L.K.E.R.   —   rendert Sterne
Antworten