Thanks for prompt responce.
<skip>
> You should probably define buf_sz:
>
[quoted text clipped - 4 lines]
> have the definition. For example, you can't pass it to a
> function, or assign it to any variable.
I thought about defining constands outside the class but
I haven't think it's UB to define them inside class definition
the way I do:(
It isn't undefined behaviour to use such an outside defined
constant as member array size?
<skip>
>> Is it a known problem? Can somebody make a suggestion how to
>
> I've not come across this, no. Without seeing a full(er)
> example, it's hard to say whether it is a compiler bug or your
> code at fault.
Unfortunalely fuller example is rather bulky and has plenty
dependences, as usual:(
And I don't have time to construct "mid-sized" examples either:(
Thanks anyway. You suggestions will certainly help.
Another question. I use template arguments and static member
consts for (maybe imaginary;) performance advantages. If member
constants are to be defined outside the class definition, it
doesn't make much sence to calculate them at compile time using
template arguments etc.? Passing arguments to class constructor
and initializing member constants in initialization list should
result in the same performance without using templates? What
would you suggest?
TIA

Signature
Serge
Tom Widmer [VC++ MVP] - 04 Nov 2005 17:17 GMT
> Thanks for prompt responce.
>
[quoted text clipped - 15 lines]
> It isn't undefined behaviour to use such an outside defined
> constant as member array size?
Static integral const variables in classes can still be defined, but you
have to leave off the initializer in the definition. I literally meant
to add the code I wrote directly below the existing class. e.g.
template <class T>
struct Foo
{
static int const Bar = 10; //value defined here
}
template <class T>
int const Foo<T>::Bar; //storage set up here - value defined above
> Unfortunalely fuller example is rather bulky and has plenty
> dependences, as usual:(
[quoted text clipped - 10 lines]
> result in the same performance without using templates? What
> would you suggest?
This point is moot given the above. Define the value in the class
definition and the compiler will use it directly where possible. The
point is that the compiler may also require the variable to have storage
defined (obvious cases include taking the variable's address and binding
it to a reference, but the standard requires it for almost any use
except using it as an array bound or as the argument to another non-type
template parameter). To clarify:
struct Foo
{
static int const Bar = 10;
int array[Bar];
};
Perfectly legal so far. But:
int main()
{
int i = Foo::Bar; //illegal
&Foo::Bar; //illegal
int const& ref = Foo::Bar; //illegal
}
//But add this to make the above all legal.
int const Foo::Bar;
Tom