0

私のエラーはすべてまったく同じものであり、その理由がわかりません。どんなアドバイスも役に立ちます。手続き型の C++ を使用する必要があります。

#include <stdio.h>

typedef struct Elem {
    float Element;
}ELEM;

typedef struct Vector {
    unsigned int size = 0;
    Elem *numbers[];
}VECTOR;

// print_vec:
//  prints the vector array if it isn't NULL
// in:
//  RefToVector - single dimensional array of Elem's
// Out:
// Returns true if the array isn't NULL and it has something to print, NULL if otherwise
bool print_vec(Vector *numbers) {
    if (numbers != NULL) {
        printf("%f", numbers);
        return true;
    }
    else {
        return NULL;
    }
}

// *alloc_vec
// Allocates an empty vector array
// In:
//  Nothing
// Out:
// A newly allocated vector array

Vector *alloc_vec() {
    Vector *numbers = new Vector;
return numbers;
}

// dealloc_vec
// deallocates array
// In: 
//  an allocated array
// out: 
// Return: True if successfull, NULL if not

void dealloc_vec(Vector *numbers) {
    delete Vector *numbers;
}

// extend_vec
// Extends the vector by one element in size
// In:
// Vector array of x elements
// Out:
// Vector array of x + 1 elements
// Return: 
// A pointer to the new vector

Vector *extend_vec(Vector *numbers, Elem) {
    Vector *bigger = alloc_vec();
    bigger->size = numbers->size + 1; // set the size of the new vector to the size of the old plus one more element
    for (int i = 0; i <= numbers->size; i++) {
        bigger[i] = numbers[i]; // step through the vectors and copy the values
    }
    bigger[bigger->size-1] = Elem; // set last place in the new vector to the new element
    return bigger;
}


// scalar_plus
// Steps through the vector elements' and adds the same value to all of them
// In:
// Reference to a vector(array)
// Out: 
// Return: reference to vector with Elem value added to each

Vector *scalar_plus(Vector *numbers, Elem) {
    for (unsigned int i = 0; i <= numbers->size; i++){
        numbers[i] = numbers[i] + Elem;
    }
    return numbers;
}

私のエラーはすべて同じです。そしてここにある

vecalc.cc:49:12: error: 'Vector' does not refer to a value
    delete Vector *numbers;
           ^
vecalc.cc:8:16: note: declared here
typedef struct Vector {
               ^
vecalc.cc:67:30: error: 'Elem' does not refer to a value
    bigger[bigger->size-1] = Elem; // set last place in the new vector t...
                             ^
vecalc.cc:4:16: note: declared here
typedef struct Elem {
               ^
vecalc.cc:64:23: warning: comparison of integers of different signs: 'int' and
  'unsigned int' [-Wsign-compare]
    for (int i = 0; i <= numbers->size; i++) {
                    ~ ^  ~~~~~~~~~~~~~
vecalc.cc:81:35: error: 'Elem' does not refer to a value
        numbers[i] = numbers[i] + Elem;
                                  ^
vecalc.cc:4:16: note: declared here
 typedef struct Elem {
                ^
vecalc.cc:98:4: error: 'Vector' does not refer to a value
                *Vector = *alloc_vec();
                 ^
vecalc.cc:8:16: note: declared here
typedef struct Vector {
               ^
vecalc.cc:99:11: error: 'Vector' does not refer to a value
                assert(&Vector == NULL)
                        ^
vecalc.cc:8:16: note: declared here
typedef struct Vector {
               ^
vecalc.cc:103:14: error: 'Vector' does not refer to a value
                print_vec(*Vector);
                           ^
vecalc.cc:8:16: note: declared here
typedef struct Vector {
               ^

それらはすべて同じなので、1つを修正する方法を見つければ、すべてを取得できると確信しています..

4

1 に答える 1

1

コンパイラは、変数名が必要な場所で型名を使用していると言っています。したがって、たとえば最初のエラーの場合、変数名が完全に欠落しており、変数名の両方または両方が存在する必要があるタイプのみが存在する場所もあります。delete numbers;

于 2016-10-30T00:39:27.843 に答える