Valarray Default Initialization?

Marc A. Lepage mlepage@molecularmining.com
Sat Apr 1 00:00:00 GMT 2000


In a class constructor, I was using code like this:

    for (int nCount = 0; nCount < nSize; ++nCount)
    {
        m_cvf.push_back(valarray<double>(nSize + 1));
    }

m_cvf is a member: vector<valarray<double> >. nSize is 2. So, this
should create a 3x2 "table", with entries initialized to zero.

When I output the table, I get this:

    0 0 0 
    3.47968 0 0 
    0 0 0 

What gives? One of those entries isn't zero!

When I use this code:

    for (int nCount = 0; nCount < nSize; ++nCount)
    {
        m_cvf.push_back(valarray<double>(0.0, nSize + 1));
    }

I get the proper output:

    0 0 0 
    0 0 0 
    0 0 0 

Is this a bug? Or something to do with my explicit constructor calls?

gcc version 2.95.2 19991024 (release)
Linux kafka 2.2.5 #1 SMP Mon Apr 12 02:29:46 EDT 1999 i686 unknown

-- 
Marc A. Lepage
Software Developer
Molecular Mining Corporation
http://www.molecularmining.com/


More information about the Libstdc++ mailing list