template array initialization

Is there a way to initialize member dimensions for every A without a constructor?
1
2
3
4
5
template<int A>
struct Matrix
{
	int dimensions[A] { 0 };
};
closed account (zb0S216C)
Yes:

1
2
3
4
int main()
{
    Matrix<10> NewMatrix = { {1, 2, 3, /*...*/} };
}

Note that the structure must be a POD (Plain Old Data) type.

Wazzak
Hmm....
Just realize that int dimensions[A] { 0 }; sets to 0 all A elements.
This is what I want.
Thanks.
closed account (zb0S216C)
chameleon wrote:
int dimensions[A] { 0 };
chameleon wrote:
"This is what I want."

Only constant and static integral data members can be initialised inside the class.

Wazzak
Last edited on
I don't put a 'static' or 'const' in front of int dimensions[A] { 0 }; and it works.
It is different from specification?
closed account (zb0S216C)
What compiler are you using? Because both MinGW 4.4.1 & Microsoft's Visual C++ 2010 compilers do not accept your code, irrespective of storage & constant qualifiers.

Wazzak
Topic archived. No new replies allowed.