user3051513
user3051513

Reputation: 13

Access Array from class in main

I would like to find the array size of an object within a class, inside my main().

main()

 Class1 ojbect1;

    short int arraySize;
    arraySize = sizeof(object1.myArray)/sizeof(object1.myArray[0]);

Class1

{
public:
    static string myArray[];
.....
};

static string myArray[10];

However i am getting this error:

error: invalid application of 'sizeof' to incomplete type 'std::string []'

Upvotes: 1

Views: 71

Answers (1)

benipalj
benipalj

Reputation: 704

In this statement:

static string myArray[10];

You are defining a new array, not the Class1::myArray.

Do it as follows:

string Class1::myArray[10];

Upvotes: 1

Related Questions