Question

#include <array>
#include <algorithm>

template<typename Type, unsigned int ArraySize>
class Vector
{
public:
    std::array<Type, ArraySize> arr;
    Vector(){ std::fill(arr.begin(), arr.end(), 0); }
    Vector(const std::array<Type, ArraySize>& input) : arr(input){}
};

#include <iostream>

int main()
{
    Vector<double, 4> a2{{1, 2, 3, 4}}; 
    std::cout << a2.arr[0];
    std::cout << a2.arr[1];
    std::cout << a2.arr[2];
    std::cout << a2.arr[3];
}

This code complies fine in Visual studio 2013 in debug and release mode, but IntelliSense gives this error when I compile:

IntelliSense: no instance of constructor "CHL::Vector::Vector [with Type=double, ArraySize=4U]" matches the argument list argument types are: ({...})

My question is this a valid code in C++? and if it is how can I stop IntelliSense from polluting my error list with this error.

Was it helpful?

Solution

The Intellisense is expecting three pairs of braces:

class Vector {
    Vector( //1 for initialization of vector
        std::array<...> //1 for initialization and 1 for internal array
    );
};

However, the language permits brace elision, which means that just two will do. I'm not sure why the compiler catches this and Intellisense doesn't, but if you're using the CTP, it could just be like last time where compiler changes were not reflected in Intellisense until the real release.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top