Reputation: 895
I'm trying to make short chrono declarations
#pragma once
#include <chrono>
class Foo//: public SINGLETON<Foo>
{
public:
using point = std::chrono::steady_clock::time_point;
using secs = std::chrono::duration_cast<std::chrono::seconds>;
using now = std::chrono::steady_clock::now();
};
So that's the whole code. First issue, this code don't want to compile. First compile error:
error: 'duration_cast<std::chrono::seconds>' in namespace 'std::chrono' does not name a type
using time_secs = std::chrono::duration_cast<std::chrono::seconds>;
Second error;
error: expected type-specifier
using time_now = std::chrono::steady_clock::now();
Now a question about usage of those, i want to use them like this;
time_point GetElapsedtTime(){return time_secs(time_now - Another_time_point ); }
Can I use them like above?
I'm trying to set time point intro a variable, then to countdown the elapsed time until it reaches 1hour for example, then when 1 hour elapses.. do something.
Upvotes: 0
Views: 114
Reputation: 16670
using
(in this context) is the equivalent of typedef
. You are giving a type a new name.
This one: using point = std::chrono::steady_clock::time_point;
is fine. std::chrono::steady_clock::time_point
is a type; you're making a new name.
This one: using secs = std::chrono::duration_cast<std::chrono::seconds>;
is not, because std::chrono::duration_cast<std::chrono::seconds>
is not a type - it is a function.
Similarly, std::chrono::steady_clock::now();
is not a type. It is a value of type std::chrono::time_point<std::chrono::steady_clock>
.
(which is what the "does not name a type" message that the compiler gave you says)
Upvotes: 1