"不是指价值" c ++程序中的错误

时间:2016-10-30 00:33:10

标签: c++ pointers procedural

我的所有错误都完全相同,我似乎无法弄清楚原因。任何意见将是有益的。我必须使用程序化的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 个答案:

答案 0 :(得分:1)

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