How to initialize a const array with size defined in template before the constructor call??

template<int s>
class something
{
public:
 const int array[s];
 something(void) // uninitialized member `something<s>::array' with `const' type `const int[s]' 
 {
 }
};

razum

Recommended Answers

All 6 Replies

An initializer list?

yes i guess...

it dont says how to initialize an array...and especially not with size defiend in the template....

It doesn't matter how the size is defined, you can't initialize an array member arbitrarily like you can with local arrays. You can default initialize it, but that's about as good as it gets, and with a const array, it's not terribly useful:

template<int s>
class something {
  const int array[s];
public:
  something(): array() {}
};

Might I recommend the std::vector class instead of an array? Or remove the const qualifier and use assignment in the constructor as a poor man's initialization.

ill try somethig.....thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.