Code: Select all
const u32 Width = 10;
const u32 Height = 10;
s32 *i[Width][Height];
Code: Select all
core::dimension2d<const u32> FieldSize(10,10);
s32 *i[FieldSize.Width][FieldSize.Height];
Code: Select all
const u32 Width = 10;
const u32 Height = 10;
s32 *i[Width][Height];
Code: Select all
core::dimension2d<const u32> FieldSize(10,10);
s32 *i[FieldSize.Width][FieldSize.Height];
00061 dimension2d<T> operator*(const T& scale) const
00062 {
00063 return dimension2d<T>(Width*scale, Height*scale);
00064 }
00065
00066 T Width, Height;
00067 };
00068
00070 typedef dimension2d<f32> dimension2df;
00072 typedef dimension2d<s32> dimension2di;
I'll ask my teacher for explanation today and post his answer.. I just hope I wont forgetarras wrote:Well I see compiler to complain but I don't really understand the problem. dimension2d is template, if I define it to be const u32 then I expect its members to be constant. But I am misunderstanding something probably...
Code: Select all
core::dimension2d<const u32> FieldSize(10,10);
core::dimension2d<const u32>* FieldSizePtr = &FieldSize;
s32 *i[(*FieldSizePtr).Width][(*FieldSizePtr).Height];
core::dimension2d<const u32> SomeOtherFieldSize(5,5);
FieldSizePtr = &SomeOtherFieldSize;
Code: Select all
union dimensionUnion
{
core::dimension2d<const u32> dim2d; // Dimension2d default constructs to 0,0.
u32 arrayOfInts[2];
}
dimensionUnion myUnion;
myUnion.arrayOfInts[1] = 5; // Are we modifying a const value here?!
Code: Select all
core::dimension2d<const u32> dim2d(5,5);
u32* intPtr = (u32*)&dim2d;
intPtr[1] = 2; // Are we modifying a const value here?!
He didn't knew the reason..MasterGod wrote:I'll ask my teacher for explanation today and post his answer.. I just hope I wont forgetarras wrote:Well I see compiler to complain but I don't really understand the problem. dimension2d is template, if I define it to be const u32 then I expect its members to be constant. But I am misunderstanding something probably...
Code: Select all
core::dimension2d<const u32> FieldSize(10,10);
s32 **i = new s32*[FieldSize.Width];
for(int p=0; p<FieldSize.Width; p++)
i[p] = new s32[FieldSize.Height];
To make things clear, when the standard says variables it does not mean class members. Even given that, the definition is still a little unclear. It seems to indicate that static data members are considered integral constant values, but that is wrong. Only const static members are integral constants. That is covered later...// 5.19 Constant expressions, paragraph 1
An integral constant-expression can involve only literals (2.13), enumerators, const variables or static data members of integral or enumeration types initialized with constant expressions (8.5), non-type template parameters of integral or enumeration types, and sizeof expressions....
There is one easy way to decide something is an integral constant or not. If you can use it in a case label in a switch statement, then it is an integral constant expression.// 9.4.2 Static data members, paragraph 4
If a static data member is of const integral or const enumeration type, its declaration in the class definition can specify a constant-initializer which shall be an integral constant expression (5.19). In that case, the member can appear in integral constant expressions.
With my job I have to be a bit of a language lawyer, so I spend a lot of time looking up things like this in the standard. I didn't happen to know why this shouldn't work, so I thought I'd look it up myself and share.MasterGod wrote:When arras started this thread it was sure to end with vitek's bidding :D