1

だから、私はこの構造体を持っています:

typedef struct {
    int day;
    int amount;
    char type[4],desc[20];
 }transaction;

そして、mainで宣言されたタイプtransactionのベクトルを設定するこの関数:

void transact(transaction t[],int &n)
 {
    for(int i=0;i<n;i++)
    {
        t[i].day=GetNumber("Give the day:");
        t[i].amount=GetNumber("Give the amount of money:");
        t[i].type=GetNumber("Give the transaction type:");
        t[i].desc=GetNumber("Give the descripition:");
    }
 }

関数のヘッダーで発生するエラーtransact()

Multiple markers at this line
- Syntax error
- expected ';', ',' or ')' before '&' token

4

2 に答える 2

6

nパラメータを参照として宣言しようとしています( int &n)。ただし、参照はC ++機能であり、Cには存在しません。

この関数はの値を変更しないためn、通常のパラメーターにします。

void transact(transaction t[],int n)

後で配列を割り当てようとしているときにもエラーが発生します。

t[i].type=GetNumber("Give the transaction type:");
t[i].desc=GetNumber("Give the descripition:");

おそらく数値を返すのでGetNumber、そこで何をしようとしているのかは明確ではありません。

于 2013-03-18T18:08:38.850 に答える
3

int &nC++には;などの参照があります。Cはしません。

を削除し&ます。

t[i].type次に、とに番号を割り当てる際に問題が発生しますt[i].desc。それらは文字列であり、そのような文字列を割り当てることはできません。おそらくvoid GetString(const char *prompt, char *buffer, size_t buflen);、読み取りと割り当てを行うために次のようなものを使用する必要があります。

GetString("Give the transaction type:", t[i].type, sizeof(t[i].type));
于 2013-03-18T18:09:01.667 に答える