Getting length of an array when passed to an object
<p>I am learning about pointers, and how they can be used to send array(size is not assigned) to objects. Ultimately i m trying to learn how arrays can be added and multipled using operator overloading instead of using "vector" in c++. </p>

<p>I defined a class named vector as follows,</p>

<pre><code>class vector
{
private:
    int len;
    int *pvec;
}
public:
    vector(int array[])
    {
        len = sizeof(array)/sizeof(*array);
        cout&lt;&lt;len&lt;&lt;endl;
        pvec = new int[len+1];
        for(int i = 0;i&lt;len;i++)
         {
            pvec[i] = *(array + i);
         }
    }
    void display()
    {
        cout&lt;&lt;"[";
        for(int i = 0;i&lt;len;i++)
        {
            cout&lt;&lt;pvec[i];
            if(i &lt; len-1)
            {
                cout&lt;&lt;",";
            }
        }
        cout&lt;&lt;endl;
    }
};
</code></pre>

<p>and i declared an object of class vector as follows</p>

<pre><code>int vec1[] = {1,2,3,4};
vector v(vec1);
</code></pre>

<p>when i try to display the elements in the vector using the member function as</p>

<pre><code>v.display();
</code></pre>

<p>the output is as follows</p>

<pre><code>2
[1,2]
</code></pre>

<p>but as you can see the length of the vector is 4, but in the output it is displayed as 2. If i try to display the length of the array in main as</p>

<pre><code>cout&lt;&lt;sizeof(vec1)/sizeof(*vec1)&lt;&lt;endl;
</code></pre>

<p>the length is displayed as 4, but if i pass the same array to the object it is displayed as 2. </p>

<p>If any one could point out a mistake in this program, i would be grateful.</p>