non-static const array class-member

Z

zoe

Is it possible to initialize a non-static const array class-member of
a fundamental type?

Something like:

class Foo{}{
public:
Foo();
private:
const int myArray[];
};

Foo::Foo() : myArray({1,2,3}) {}

this does not work of course. But is it possible in some other way?

regards
Zoe
 
R

Ron Natalie

zoe said:
Is it possible to initialize a non-static const array class-member of
a fundamental type?

No, there is no such thing as an array literal.
You can't use the aggregate initalizer (the { .. } stuff)
other than after the = in a declaration.
 
X

Xenos

zoe said:
Is it possible to initialize a non-static const array class-member of
a fundamental type?

Something like:

class Foo{}{
public:
Foo();
private:
const int myArray[];
};

Foo::Foo() : myArray({1,2,3}) {}

this does not work of course. But is it possible in some other way?

regards
Zoe

How about:

class Foo {
public:
struct Array {
int a[N];
};

Foo();

private:
const Array myArray;
};

Foo::Foo(const Array& a) : myArray(a) {}


for some constant N, or make Foo a template class as in
template<typename N>
Foo
.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top