Class Static Array field change value suddenly(C++)
<p>this is snippet of Block class :</p>

<pre><code>class Block { public:
    //size satu blok(dalam byte)
    static const int BLOCK_SIZE = 4096;    

    Block(int number,byte *data):number(number) {        
       for(int i=0;i&lt;BLOCK_SIZE;i++) {
           this-&gt;data[i] = data[i];         
       }    
    }

    void test();
     private:
    byte data[BLOCK_SIZE];    
    const int number; };
</code></pre>

<p>note that byte is just typedef unsigned char</p>

<p>and this is one of the function in other class that initialize block variable</p>

<pre><code>bool Filesystem::getBlock(int number, Block *block) {        
    fstream fin(path);
    if(!fin.is_open() || number&lt;0) {
        return false;
    }
    byte data[Block::BLOCK_SIZE];        
    fin.seekg(Block::BLOCK_SIZE*number,ios::beg);                       
    for(int i=0;i&lt;Block::BLOCK_SIZE;i++) {
        fin&gt;&gt;data[i];                
    }
    block = new Block(number,data);    
    (*block).test();//this is the first test, this prints values as expected
    fin.close();
    return true;
}
</code></pre>

<p>this is another snippet : </p>

<pre><code>Block *superblock;
getBlock(0,superblock);
(*superblock).test();//this is the second test, this prints random value
</code></pre>

<p>test is a function that prints the first four bytes from data in block
when i first use the test function inside the getblock, it prints exactly like i wanted(same as the file) but when i tried to print it the second time exactly after i call getblock, it prints random value</p>

<p>anyone knows where the mistake?</p>
