Aşağıdaki kod derliyor (g++ 4.7.2
) time_point eklemek:std :: Chrono: özel süre
#include <chrono>
typedef std::chrono::duration<double> double_prec_seconds;
typedef std::chrono::time_point<std::chrono::system_clock> timepoint_t;
void do_something(const timepoint_t& tm)
{
// ...
}
int main(int argc, char** argv)
{
timepoint_t t0 = std::chrono::system_clock::now();
timepoint_t t1 = t0 + std::chrono::seconds(3);
// timepoint_t t3 = t0 + double_prec_seconds(3.14);
auto t3 = t0 + double_prec_seconds(3.14);
do_something(t1);
}
Sorunum t3
sahiptir ne tür bilmiyorum olmasıdır. timepoint_t
değil ve açık bir şekilde verilen satırın yorumlanması derlenmeyecekti. Fonksiyon çağrısı ile aynı: t3
ile do_something
'u arayamıyorum.
Yani benim sorular şunlardır:
- Neden dönüşüm başarısız oluyor?
- Çift duyarlıklı saniye sürelerine sahip olmanın en iyi yolu nedir?
Ben bu
// this works
timepoint_t t3 = t0 + std::chrono::duration_cast<std::chrono::milliseconds>(double_prec_seconds(3.14));
gibi ek bir döküm kullanabileceğinizi biliyor ama bunu önlemek istiyorum.
şimdiden teşekkür ederiz! En kolay yolu time_point
bir şablon parametresi olarak double_prec_seconds
vermek olacaktır
std::chrono::time_point< std::chrono::system_clock,
std::chrono::duration<double> >
için
std::chrono::time_point< std::chrono::system_clock,
std::chrono::system_clock::duration >
hiçbir dönüşüm, bkz olduğundan
Tipik (t3) .name(), borulama stdout'unu C++ filtresine kullanarak t3'ün türünü yazdırdım ve "std :: chrono :: time_point>>. Sadece FYI. –
Aletle ilgili ipucu için TEŞEKKÜR EDERİZ! Temelde aynı şeyi yaptım, sadece C++ filtresi olmadan ve şifreli bir isim dışında hiçbir şey "yararlı" aldım. 'C++ filt' yardım ediyor gibi görünüyor, bunu bilmiyordum. –