C
Christopher Pisz
I need to define the size of an array at compile time.
The size I need to use is a static constant unsigned long which is a
public class member in another library.
The compiler complains that "expected constant size"
If I try to use keyword extern, it compains that it is a class member
and I cannot use keyword extern on it.
I am not quite sure why the compiler does not think this is a constant
which is defined at compile time or how I can use it in my array
declaration. I could just allocate an array or use a std::vector, but
one must learn when one comes across things he does not understand.
Here is what I am trying
// When I include the header from the library, it is linked via
// compiler specific code.
#include "OtherClass.h"
int main()
{
unsigned long myArray[OtherNamespace::OtherClass::MAX_SIZE];
return 0;
}
----------------
Then in the other library:
In the OtherClass.h
namespace OtherNamespace
{
MyClass
{
public:
// REMOVED irrelevant code
static const unsigned int MAX;
};
}
--------------
In the OtherClass.cpp
namespace OtherNamespace
{
const unsigned int OtherClass::MAX_SIZE = 16;
}
The size I need to use is a static constant unsigned long which is a
public class member in another library.
The compiler complains that "expected constant size"
If I try to use keyword extern, it compains that it is a class member
and I cannot use keyword extern on it.
I am not quite sure why the compiler does not think this is a constant
which is defined at compile time or how I can use it in my array
declaration. I could just allocate an array or use a std::vector, but
one must learn when one comes across things he does not understand.
Here is what I am trying
// When I include the header from the library, it is linked via
// compiler specific code.
#include "OtherClass.h"
int main()
{
unsigned long myArray[OtherNamespace::OtherClass::MAX_SIZE];
return 0;
}
----------------
Then in the other library:
In the OtherClass.h
namespace OtherNamespace
{
MyClass
{
public:
// REMOVED irrelevant code
static const unsigned int MAX;
};
}
--------------
In the OtherClass.cpp
namespace OtherNamespace
{
const unsigned int OtherClass::MAX_SIZE = 16;
}