From: Christian H. Kuhn on
Me stupid.

Working:
int main()
{
int testarray[] = { 0, 1, 2};
return 0;
}

Not working:
class testclass
{
public:
static const int testarray[] = { 0, 1, 2};
};


int main()
{
testclass Testobjekt;
return 0;
}

Why is the second example wrong? How should i do that?

TIA
Chris
From: "sk_usenet" sometechyguy at gmail dot on
"Christian H. Kuhn" <christian.kuhn(a)qno.de> wrote in message.
> Me stupid.
>
> Working:
> int main()
> {
> int testarray[] = { 0, 1, 2};
> return 0;
> }
>
> Not working:
> class testclass
> {
> public:
> static const int testarray[] = { 0, 1, 2};
> };
>

class testclass
{
public:
static const int testarray[];
};

const int testclass::testarray[] = {1, 2, 3}; // Definition

> int main()
> {
> testclass Testobjekt;
> return 0;
> }
>
> Why is the second example wrong? How should i do that?


Note that there are special rules for placing an initializer within the
class for static const integral types (C++ Standard 9.4.2/4). But for your
purposes you'd be good to always define them outside the class.

--
http://techytalk.googlepages.com


 | 
Pages: 1
Prev: ostream_iterator
Next: throw msg macro