Solved

# Determining array length

Posted on 2004-08-11

Actually, this question has two parts.

1. Can C++ arrays only hold primitive types such as int, float, etc? Can it hold abstract types such as:

class A {

...

};

int main() {

A a1, a2, a3;

A a[] = {a1, a2, a3};

myFunc(a); // see part 2

return 0;

}

2. Now for my real question. When passed an array as a parameter, how do I determine the length of the array? This array contains abstract types.

From the example above, suppose I have the following function

void myFunc(A *x) {

// how do I find the length of the array

}

In C, I know that you can do the following

int size = sizeof(x) / sizeof(x[0]);

Thanks a lot everyone.

P.S. I am interested only in arrays. Not vectors.