Const array

Thread Starter

mentaaal

Joined Oct 17, 2005
451
Hi guys,

quick question, just wandering is it possible to define a const array of anything as a data member of a class?

Below is an example of what I mean (THis code does not compile by the way!)

Rich (BB code):
#include <iostream>
using namespace std;

class test
{
public:
    test();
    void output();
private:
    const char A[2] = {'h','d'};
};

test::test()
{
    //do nothing
}
void test::output()
{
    cout << A[0];
    cout << A[1];
}

int main()
{
    test test1;
    test1.output();
}
 

Mark44

Joined Nov 26, 2007
628
const arrays in C++ are pretty dim in my memory, and I wasn't able to find out anything about them in 3 or 4 references. It's possible that they have to be initialized in the class constructor. Or make the array static.
 
Top