There's also a template option, something like this?
class static_class
{
public:
template<int I>
static_class(int (&array)[I])
{
std::cout << I << std::endl;
}
};
I think that'd work, anyway. sizeof(array)/sizeof(array[0]) only works in scopes where the array's definition is actually visible. In other words, your static_class constructor couldn't "see" the size of the array, all it knew was that it was getting an array of some (any) size. You could pass an array of 100 elements or four, and the function itself would get no information.
In my example, on the other hand, the template will cause one version of the function to be created for each array size that you pass in. This may or may not be desirable. Generally speaking, it's best to keep the array size somewhere handy, like:
class my_class
{
public:
static static_class s;
static const int array_size = 4;
static int array[array_size];
};
Then you can pass my_class::array_size around and not have to be worried about what the compiler may or may not have visible regarding array attributes.