Boca Bogdan
Boca Bogdan

Reputation: 15

vector was not declared in this scope

I am trying to solve this problem, but I receive this

error : 'vector' was not declared in this scope.

Here is the struct definition that's included in a header file, and the code.

struct Vector
{
    unsigned int length;
    int values[MAX_ARRAY_LENGTH];
};


Vector getSquares(double a, double b, double c)
{
vector.length=0;
float minim=min(a, b, c);
float maxim=max(a, b, c);
int i;
for(i=sqrt(minim); i<=maxim; i++)
   {
    if((i*i<=maxim)&&(i*i>=minim))
    vector.values[vector.length]=i;
    vector.length++;
   }
   return vector;
}

Upvotes: 0

Views: 4336

Answers (3)

Akshay
Akshay

Reputation: 46

The structure definition included from header file is just a definition i.e. a new user defined data type. However to use this datatype you need to create/declare an object/variable. As suggested in previous answers you need to declare a variable of this structure/data type(just like declaring 'int i' for using an integer variable named 'i') before using it - in your case would be 'vector'. Just declare a variable in the beginning of the function

Vector vector;

Upvotes: 1

Viktor Liehr
Viktor Liehr

Reputation: 538

Actually vector is really not declared in this scope... The compiler does now what type vector is.

First declare a variable, and then use it.

Vector vector;
// your code 

Upvotes: 2

ForeverStudent
ForeverStudent

Reputation: 2537

I am guessing by:

vector.length=0 

you are trying to initialize a vector object that is initially empty;

for that you will need to do:

Vector vector;
vector.length=0;

Upvotes: 3

Related Questions