Q:

What's the difference between global variables and inside class?

#include "stdafx.h"
#include "CppUnitTest.h"
#include <iostream>
#include <cstdlib>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest2

{       
    TEST_CLASS(UnitTest1)
    {
    public:

        int vector [6] = { 14, 10, 11, 19, 2, 25 };
        bool ArrayAreEqual;
        int static compare(const void * x1, const void * x2) 
        {
            return (*(int*)x1 - *(int*)x2); 
        }

        TEST_METHOD(TestMethod1)
        {
            qsort(vector, 6, sizeof(int), compare); 
            for (int ix = 0; ix < 6; ix++)
                std::cout << vector[ix] << " ";
            // TODO: Your test code here

            int TestVector[6] = { 2,10,11,14,19,25 };
            if (std::equal(std::begin(vector), std::end(vector), std::begin(TestVector)))
            {
                ArrayAreEqual = true;
            }

            else
            {
                ArrayAreEqual = false;
            }
            Assert::IsTrue(ArrayAreEqual);

        }

    };
}

In my code the int vector [6] = { 14, 10, 11, 19, 2, 25 }; only can be defined with numbers of elements [6] (otherwise it shows incomplete type is not allowed) , but if this variables are global, it can be defined without size, like int vector [] = { 14, 10, 11, 19, 2, 25 };
Why does this happens?

A:

Unlike all other initializers, in-class (non-static) member initializers can be overridden by a constructor's member initializer list.  Since they might be ignored, they cannot be used to specify the length of an array.

