|
Boost Users : |
From: Duane Murphy (duanemurphy_at_[hidden])
Date: 2002-01-15 21:03:06
--- At Tue, 15 Jan 2002 17:50:36 -0800, Duane Murphy wrote:
>Below is a simple example that I cannot get to compile. I would like to
>create a subclass of boost::array in order to give it some additional
>functionality (I would like a associative array like interface).
>
>When I compile this, I get an "illegal initialization" error for test.
>
>I am using Metrowerks Codewarrior 7 on Mac OS X.
>
>Is there some special incantation required? I suspect that I am in some
>kind of specialized area and I cant get there from here.
>
>template < class T, std::size_t N >
>struct test_array : public boost::array< T, N >
>{
>};
>
>static boost::array< char,1 > array_test = {{ 'a' }};
>static test_array< char, 1 > test = {{ 'a' }};
>
>It appears that if I aggregate instead of inherit that this might work
>(at least it compiles :-)
>
>template < class T, std::size_t N >
>struct test_array
>{
> boost::array< T, N > array_;
>};
>
>static boost::array< char,1 > array_test = {{ 'a' }};
>static test_array< char, 1 > test = {{ 'a' }};
>// The funny thing is this works also:
>static test_array< char, 1 > test2 = { 'a' };
I'll just answer my own question.
Aggregation makes a difference. The use of single braces instead of
triple is likely caused by the degenerate single item initialization.
It does in fact require three curly braces as one would expect as there
are three nested structures defined.
I guess this is why aggregation works. I would like to understand why
inheritance doesnt.
...Duane
p.s.
I mostly have a "static map" working.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net