Boost logo

Boost Users :

From: Daryle Walker (darylew_at_[hidden])
Date: 2006-04-06 19:45:55


On 4/5/06 4:48 PM, "Karim Bakir" <rimbak_at_[hidden]> wrote:

You should first start by putting in a descriptive subject to your message.
A generic "help" sentence, especially one that is misspelled and
over-emphasized, is no good. Also, since Boost covers a lot of different
code subjects, you should add a tag to the subject specifying the library
you have a problem with.

> I use multi array boost
>
> But I have problem : - I can't declare a multi array as a member variable ,
> I have the error: unexpected "error C2321: syntax error : unexpected
> 'boost::extents"
> When I don' write the keyword "typdef" I have more mistakes.

The actual problem isn't with multi-array; it's that you can't write a
class.

>
> //Boost library
> #include <Boost/multi_array.hpp>
> #include <cassert>
> //Name Space
> using namespace std;
> using namespace boost;
> class MyClass
> {
> typedef boost::multi_array<double,2>array_type_2d;
>
> public:
>
> MyClass();
> virtual ~MyClass();
> array_type_2d M(boost::extents[10][10]);
>
> };
[TRUNCATE]

Data-based members generally cannot be initialized at the declaration level
within the class definition. (The exception is for static data member
constants of an integer or enumeration type, and they must use the "= Value"
syntax.) You should initialize non-static data members within each
constructor, hopefully within the initializer list, or within the body if
you must. Static data members that don't meet the exception given above
have to be initialized like a regular variable, but outside the class
definition.

//========================================================================
class MyClass2
{
    boost::multi_array<double, 2> M;

    static const std::size_t sz = 10u;

    static float count;

public:
    MyClass2()
        : M( boost::extents[sz][sz] )
    {
        ++count;
    }

    virtual ~MyClass2() { --count; }
};

float MyClass2::count( 0.0f );
//========================================================================

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

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