I have this code:
#include <iostream>
using namespace std;
class hello
{
private:
char array[4][5];
public:
hello();
void get_hello(){cout << "From the function: array[2][2] = " << array[2][2] << endl;}
} hi;
hello::hello()
{
char array[4][5] =
{
" ###",
"####",
"####",
"####"
};
cout << "From the constructor: array[2][2] = " << array[2][2] << endl;
(*this).get_hello();
}
int main()
{
hi.get_hello();
cout << "\n" << "Press Enter to end this programm";
cin.get();
cout << endl;
return 0;
}
Output:
>From the constructor: array[2][2] = #
>From the function:array[2][2] =
>From the function:array[2][2] =
I know I can't acces the array because I replaced it with an automatic version in the contructor. What would be the correct syntax to set the class variable that way?
I have tried:
array[4][5] =
{
" ###",
"####",
"####",
"####"
};
and
array =
{
" ###",
"####",
"####",
"####"
};
but neither of them worked. Can you set an class variable that way or do I have to make an programm that autogenerates code that set the
variable's like:
array[0][0] = ' ';
array[0][1] = '#';