The type of a member within a class seems to affect the initialization of other members within the class

1

Commenting and uncommenting the following statement, with significant differences in results. I am a C++ rookie, and I am very confused at this problem. I use Visual Studio 2015 Enterprise and Windows 10 64bit.

class Test
{
private:
    double d;
    float f;
    int i;
    int *pt;
    //Commenting and uncommenting this statement, with significant differences in results.
    std::shared_ptr<int> spt;
};

int main(int argc, char** argv)
{
    Test t;

    return 0;
}

When commented, the result:

         t  {d=-9.2559631349317831e+61 f=-107374176. i=-858993460 ...}  Test
         d  -9.2559631349317831e+61 double
         f  -107374176. float
         i  -858993460  int
         pt 0xcccccccc {???}    int *

When uncommented, the result:

         t  {d=0.00000000000000000 f=0.000000000 i=0 ...}   Test
         d  0.00000000000000000 double
         f  0.000000000 float
         i  0   int
         pt 0x00000000 {???}    int *
         spt    empty   std::shared_ptr<int>
c++
c++11
visual-studio-2015
initialization
asked on Stack Overflow Oct 16, 2019 by Tango Xiao • edited Oct 16, 2019 by user3365922

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0