As stated sizeof f
is the size of the pointer not the size of the object where it points to, as also said, using STL containers is a much better option given that they have size members that keep track of the size of the container.
That being said, if you're adamant in using a C style array, a solution would be to wrap it in a struct
or class
and return the size from there, i.e:
struct myArray
{
const int triTable[4][6] = {
{},
{0, 8, 3},
{0, 1, 9},
{1, 8, 3, 9, 8, 1},
};
const int size = std::size(triTable[3]); // size data member
int arraySize() const{
return std::size(triTable[3]); // size method
}
};
int main()
{
myArray a;
std::cout << a.size << "\n";
std::cout << a.arraySize();
}
Output:
6
6