I\'ve a constant struct timespec
member in my class. How am I supposed to initialize it?
The only crazy idea I got is to derive my own timespec
Use an initialization list with a helper function:
#include
#include
#include
class Foo
{
private:
const timespec bar;
public:
Foo ( void ) : bar ( build_a_timespec() )
{
}
timespec build_a_timespec() {
timespec t;
if(clock_gettime(CLOCK_REALTIME, &t)) {
throw std::runtime_error("clock_gettime");
}
return t;
}
};
int main() {
Foo foo;
return 0;
}