Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Initialize a static const matrix

48 views
Skip to first unread message
Message has been deleted

red floyd

unread,
Jul 31, 2016, 4:34:24 PM7/31/16
to
On 7/31/2016 10:26 AM, Mark wrote:
>
> Consider:
>
> # include <iostream>
> # include <cstring >
>
> template < size_t Rows, size_t Cols, typename ElemType = double >
> class TestMatrix
> {
> public :
> ElemType elems[Rows ] [ Cols ];
>
> //ElemType elems[Rows * Cols ];
> };
>
> class Foo
> {
> static const TestMatrix < 2, 2 > test ;
> static const unsigned int val[2][2]; // Specify all dimensions.
> public :
> Foo () ;
> };
>
>
> Foo::Foo()
> {
>
> }
>
> // works C style for multi-dimensional
> const unsigned int Foo::val[][2] = { { 0, 1 } , { 2, 3 } };
>
> const TestMatrix < 2, 2 > Foo::test =
> { { 0.1, 1.1 } , { 2.2, 3.2 } };
>
>
> int main()
> {
>
> }
>
> The compiler I'm using has no C++11 support, that said, how can I initialize the static const test member within Foo? Unclear why the initialization of test fails when the TestMatrix effectively mimics the c-style approach to a multi-dimensional array
>
> Thanks in advance
>
If all you have is C++03 support, then provide a constructor that takes
an N by M array

Öö Tiib

unread,
Aug 1, 2016, 5:07:41 PM8/1/16
to
On Sunday, 31 July 2016 20:26:46 UTC+3, Mark wrote:
> Consider:

OK, I will.

>
> # include <iostream>
> # include <cstring >

I trust that you must type here:

# include <cstring>

Otherwise it looks like syntax error.

>
> template < size_t Rows, size_t Cols, typename ElemType = double >
> class TestMatrix
> {
> public :
> ElemType elems[Rows ] [ Cols ];
>
> //ElemType elems[Rows * Cols ];
> };
>
> class Foo
> {
> static const TestMatrix < 2, 2 > test ;
> static const unsigned int val[2][2]; // Specify all dimensions.
> public :
> Foo () ;
> };
>
>
> Foo::Foo()
> {
>
> }
>
> // works C style for multi-dimensional
> const unsigned int Foo::val[][2] = { { 0, 1 } , { 2, 3 } };
>
> const TestMatrix < 2, 2 > Foo::test =
> { { 0.1, 1.1 } , { 2.2, 3.2 } };

I trust that you must type here:

const TestMatrix < 2, 2 > Foo::test =
{ { { 0.1, 1.1 } , { 2.2, 3.2 } } };

Otherwise it looks like syntax error.

>
>
> int main()
> {
>
> }

So?

>
> The compiler I'm using has no C++11 support, that said, how can I
> initialize the static const test member within Foo? Unclear why
> the initialization of test fails when the TestMatrix effectively
> mimics the c-style approach to a multi-dimensional array
>
> Thanks in advance

You did not tell what your problem was besides two obvious syntax
errors. Oh well.
0 new messages