"Does not refer to value" C++ 过程中的错误



我所有的错误都是完全相同的事情,我似乎不知道为什么。任何建议都会有帮助的。我必须使用程序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 {
               ^

,因为它们都是一样的,我敢肯定,如果我知道如何修复一个,我就会得到所有的。

编译器告诉您,您在变量名应该使用的地方使用了类型名称。例如,对于第一个错误,应该只有delete numbers;还有一些地方,你直接错过了变量名,只有类型,其中两个或只有变量名。

相关内容

  • 没有找到相关文章

最新更新