Reputation: 6613
Since I cant seem to make the constructor for my conversion class static, I tried faking it but its giving me an error about unresolved externals:
struct FloatConversions {
static std::array<float, 256> ByteLUT;
struct Initializer {
Initializer() {
for (double i = 0; i < 256; i++) {
ByteLUT[i] = i / 255.0;
}
}
};
Initializer Init;
static inline float ByteToFloat(int val) {
return ByteLUT[val];
}
static inline uint8_t FloatToByte(float val) {
return static_cast<uint8_t>(val * 255.0f);
}
};
typedef FloatConversions FC;
what could be the problem?
Upvotes: 2
Views: 1298
Reputation: 21773
Here is a simple solution that does the job.
float ByteToFloat(int val)
{
static const struct FloatConversions
{
std::array<float, 256> ByteLUT;
FloatConversions()
{
for (int i = 0; i < 256; i++)
{
ByteLUT[i] = i / 255.0f;
}
}
} conveter;
return conveter.ByteLUT[val];
}
Upvotes: 5