static array in c++ forgets its size
<p>In this small example, c++ forgets size of an array, passed to a constructor. I guess it is something simple, but I cannot see it.</p>

<p>In classes.h, there is this code:</p>

<pre><code>#ifndef CLASSES_INC
#define CLASSES_INC
#include &lt;iostream&gt;

class static_class {
 public:
 static_class(int array[]) {
  std::cout&lt;&lt;sizeof(array)/sizeof(int)&lt;&lt;"\n";
 } 
};

class my_class{
 public:
 static static_class s;
 static int array[4];
};

#endif
</code></pre>

<p>In classes.cpp, there is this code:</p>

<pre><code>#include "classes.h"

int my_class::array[4]={1, 2, 3, 4}; 

static_class my_class::s = static_class(my_class::array);
</code></pre>

<p>In main.cpp, there is only simple</p>

<pre><code>#include "classes.h"

int main () {

 return 0;
}
</code></pre>

<p>Now, the desired output (from the constructor of static_class) is 4. But what I get is 1. Why is that?</p>

<p><strike>edit:</p>

<p>A lot of answers suggest that sizeof on pointer returns the size of a pointer. That is not true, AFAIK (from <a href="http://msdn.microsoft.com/en-us/library/4s7x1k91(VS.71).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/4s7x1k91(VS.71).aspx</a> - "When the sizeof operator is applied to an array, it yields the total number of bytes in that array, not the size of the pointer represented by the array identifier.")</strike></p>

<p>edit2:</p>

<p>ok, as I found out, when compiler can see the size, sizeof returns the whole size, but when it decays to a pointer (which is the case here), sizeof actually really returns size of pointer.</p>
