2016-05-06 23 views
0

Ich habe Probleme mit der Zuweisung eines Werts an cv. Basierend auf meinen Code unten, ich bin immer error: invalid initializer an der Linie:Ungültiger Initialisierer - Array von Strukturen

ChVec cv = r->cv; 

Würde jemand wissen, was das Problem sein könnte?

Danke für Ihre Hilfe.

tuple.c

#include "defs.h" 
#include "tuple.h" 
#include "reln.h" 
#include "hash.h" 
#include "chvec.h" 
#include "bits.h" 

Bits tupleHash(Reln r, Tuple t) 
{ 
    ChVec cv = r->cv; 
    ... 
    ... 
} 

chvec.h

#include "defs.h" 
#include "reln.h" 

#define MAXCHVEC 32 

typedef struct { 
    Byte att; 
    Byte bit; 
} ChVecItem; 

typedef ChVecItem ChVec[MAXCHVEC]; 

reln.h

#ifndef RELN_H 
#define RELN_H 1 

typedef struct RelnRep *Reln; 

#include "defs.h" 
#include "tuple.h" 
#include "chvec.h" 
#include "page.h" 


struct RelnRep { 
    Count nattrs; // number of attributes 
    Count depth; // depth of main data file 
    Offset sp;  // split pointer 
    Count npages; // number of main data pages 
    Count ntups; // total number of tuples 
    ChVec cv;  // choice vector 
    char mode; // open for read/write 
    FILE *info; // handle on info file 
    FILE *data; // handle on data file 
    FILE *ovflow; // handle on ovflow file 
}; 
+1

Bitte senden Sie uns eine [Minimal, vollständig und prüfbare Beispiel] (http://stackoverflow.com/help/mcve). –

+0

- Der Link wird Ihnen helfen. http://stackoverflow.com/questions/3635053/how-to-copy-array-of-struct-in-c – techEmbedded

Antwort

2

Der Typ ChVec ist ein Array, Sie können ein Array nicht mit einem anderen Array initialisieren (genau wie Sie es einer Array-Variablen nicht zuweisen können).

Stattdessen müssen Sie Kopie das Array:

ChVec cv; 
memcpy(cv, r->cv, sizeof cv); 
2

Arrays können nicht die Art und Weise zugeordnet werden Sie tun.

Sie müssen memcpy() verwenden Inhalt zu kopieren:

ChVec cv; 
memcpy(cv, r->cv, sizeof(cv));