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

boost array Compile fehler

9 views
Skip to first unread message

Jens Kallup

unread,
Apr 10, 2012, 11:08:01 AM4/10/12
to
Hallo Gemeinde,

wo steckt hier der Fehler?
siehe Kommentare ...
Gruß
Jens

#include "boost/multi_array.hpp"
#include "boost/multi_array/base.hpp"
#include "boost/multi_array/collection_concept.hpp"
#include "boost/multi_array/copy_array.hpp"
#include "boost/multi_array/iterator.hpp"
#include "boost/multi_array/subarray.hpp"
#include "boost/multi_array/multi_array_ref.hpp"
#include "boost/multi_array/algorithm.hpp"
#include "boost/array.hpp"
#include "boost/mpl/if.hpp"
#include "boost/type_traits.hpp"

#include <stdio.h>
#include <QString>
#include <QMap>
#include <QList>

#include <iostream>
using namespace std;

class TArrayType
{
private:
int type;

typedef boost::multi_array<double, 16> array_type_double;
//array_type_double A(boost::extents[3]); // Error:
test.cc:27:32: error: 'boost::extents' is not a type
array_type_double A;

boost::array<array_type_double::index, 16> array_index;

public:
TArrayType(void) { }
TArrayType(int MemArray[16], double val)
{
type = 1;
// Error: runtime Error
boost::array<array_type_double::index, 16> array_index = { { *MemArray } };
A(array_index) = val;
}

double getDouble(void) { return A(array_index); }
};

QMap<QString, TArrayType> ArrayList;

int main(int argc, char **argv)
{
int memarr[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
ArrayList.insert("Array1",TArrayType(memarr,(double)42));

TArrayType at;
double val = ArrayList["Array1"].getDouble();
cout << val << endl;

return 0;

// This rest works fine ...

typedef boost::multi_array<double, 1> array_type;
array_type A(boost::extents[3]);

boost::array<array_type::index, 3> idx1 = { {0,0,0} };
boost::array<array_type::index, 3> idx2 = { {1,2,1} };

A(idx1) = 3.14;
A(idx2) = 42;

cout << A(idx1) << endl << A(idx2) << endl;


boost::array<array_type::index, 5> idx3 = { {1,2,1,2,0} };

A(idx3) = 1234;

cout << A(idx3) << endl;

return 0;
}

Daniel Krügler

unread,
Apr 10, 2012, 3:18:53 PM4/10/12
to
Am Dienstag, 10. April 2012 17:08:01 UTC+2 schrieb Jens Kallup:
> Hallo Gemeinde,
>
> wo steckt hier der Fehler?

Da sind gleich mehrere...

> class TArrayType
> {
> private:
> int type;
>
> typedef boost::multi_array<double, 16> array_type_double;
> //array_type_double A(boost::extents[3]); // Error:
> test.cc:27:32: error: 'boost::extents' is not a type

A ist eine Elementdeklaration mit gleichzeitiger Initialisierung.
Das ist in der Form nicht möglich in C++. Entweder du verwendest
einen C++11-konformen Compiler (gcc 4.7 z.B.) und definierst mit geschweiften Klammern z.B.:

array_type_double A{boost::extents[3]};

oder du machst es nach guter alter Manier so, das du die Initialisierungsliste des Konstruktors verwendest.

Das zweite Problem oben ist, dass deine Aufteilung deines Arrays keinen
Sinn macht: Die Benutzung von extents in obiger Form setzt voraus, dass du für *jede* der 16 Dimensionen eine Länge angibst. Da fehlen also noch 15 Längenangaben in eckigen Klammern. Bist du sicher, dass du ein 16-dimensionales Feld beschreiben willst?

Besten Gruss aus Bremen,

Daniel Krügler
0 new messages