I'm new to C and am exploring the use of timezones in chrono, specifically zoned_time. I have only one issue with it: I want to use an instance of zoned_time as a member in a class, but no matter how I alter the syntax, the compiler doesn't like it.
#include <chrono>
#pragma once
class Event
{
private:
std::chrono::zoned_time tz;
public:
Event();
};
I've created a header file containing the code above, but it says the argument list for the class template is missing. I assume that means it wants me to initialize it, but I don't want to because it's a header file. As I said, I messed around quite a bit with the syntax of tz, combined with a good bit of research. Unfortunately, since I'm new to the language I really don't know what to look for online.
So my goal here is to be able to create a typed container within Event which will store the zoned_time information. I'm not picky on how I achieve that goal (I suspect some black-magic pointer trickery will be the solution). Thank you for the input.
CodePudding user response:
Your error message mentions the word "template", indicating it's not about constructor arguments (initializer), but about generic type arguments (template parameters).
According to https://en.cppreference.com/w/cpp/chrono/zoned_time this class is declared as:
template <
class Duration,
class TimeZonePtr = const std::chrono::time_zone*
> class zoned_time;
So it seems like you need a duration type to use (there is a default for the time zone pointer type). So your line should probably say something like
std::chrono::zoned_time<std::chrono::seconds> tz;