J
Jason Heyes
What STL algorithm do I use to set all bool elements of an array to false in
just one line of code? Thanks!
just one line of code? Thanks!
What makes you believe that you need an algorithm to do that?
Jason said:What makes you believe that you need an algorithm to do that?
Here is why.
class Array {
bool arr[10];
public:
Array() { /* initialise arr */ }
};
What do I put in place of the comment if I want to initialise arr in just a
single line of code?
Jason said:What makes you believe that you need an algorithm to do that?
Here is why.
class Array {
bool arr[10];
public:
Array() { /* initialise arr */ }
};
You can default initialize member arrays using the following syntax:
Array() : arr() { ... }
you cannot !
there is no std default contruction of integers, boolean etc.
"arr()" doesn't mean anything here and you have to do a loop
Jason said:I tried this in a small program and it did not initialise the array.
Are you claiming that the following program can print anything other than
the number zero?
#include <iostream>
using namespace std;
struct Foo
{
int i;
Foo() : i() { cout << i << endl; }
};
int main()
{
Foo foo;
}
Jason said:There is no default initialisation of integers, boolean, etc, in arrays.
you cannot !
there is no std default contruction of integers, boolean etc.
"arr()" doesn't mean anything here and you have to do a loop
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.