Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "An array may not have elements of this type"

Tags:

c++

arrays

I`ve problem compiling my program because of this strange compile error...here is the concrete part of code:

 // the error occures at "char _adr[][]" in the constructor parameters

Addresses(string _ime, string _egn, char *_adres, char _adr[][], int adrLen):Person(_ime, _egn, _adres){
    addressLength = 0;
    for(; addressLength < adrLen; addressLength++) {
        if(addressLength >= 5){
            break;
        }
        adr[addressLength] = _adr[addressLength];
    }
}
like image 503
user2976091 Avatar asked Jan 12 '14 19:01

user2976091


1 Answers

In C/C++ you cannot define a bi-dimensional array with two unknown size as in char _adr[][]. Arrays declarations must have all, but the first, sizes defined. Try defining at least one size (example: char _adr[][10]) or, since you are using C++, use an std::vector instead.

Just to make you notice it: you are also using the adr without declaring it in the scope of the function.

like image 82
Shoe Avatar answered Oct 04 '22 17:10

Shoe