By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

non-static const array class-member

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"zoe" <zo*********@yahoo.com> wrote in message
news:73**************************@posting.google.c om...
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.

Jul 22 '05 #2

P: n/a

"zoe" <zo*********@yahoo.com> wrote in message
news:73**************************@posting.google.c om...
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
.....


Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.