error: conversion from ‘time_point<std::chrono::_V2::system_clock,duration<[...],ratio<[...],1000000000>>>’ to non-scalar type ‘time_point<sgamr::common::UniversalTimeScaleClock,duration<[...],ratio<[...],10000000>>>’ requested 69 | ::sgamr::common::Time timestamp = Time_Start;
时间: 2024-01-21 07:02:10 浏览: 279
根据错误信息,你尝试将 std::chrono::system_clock::time_point
类型的对象赋值给 sgamr::common::Time
类型的变量。然而,这两个类型不兼容,不能直接进行赋值。
要解决这个问题,你需要编写一个适当的转换函数来将 std::chrono::system_clock::time_point
转换为 sgamr::common::Time
类型。在转换函数中,你可以提取 std::chrono::system_clock::time_point
对象的时间信息,并使用它来构造一个 sgamr::common::Time
对象。
示例代码如下所示:
#include <chrono>
#include "sgamr/common/time.h"
sgamr::common::Time convertToSgamrTime(const std::chrono::system_clock::time_point& timePoint) {
// 提取时间信息并构造 sgamr::common::Time 对象
std::chrono::nanoseconds duration = timePoint.time_since_epoch();
int64_t nanoseconds = duration.count();
sgamr::common::Time sgamrTime;
sgamrTime.nanoseconds_since_epoch = nanoseconds;
return sgamrTime;
}
int main() {
std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
// 调用转换函数将 std::chrono::system_clock::time_point 转换为 sgamr::common::Time
sgamr::common::Time sgamrTime = convertToSgamrTime(timePoint);
// 使用转换后的 sgamr::common::Time 对象
// ...
return 0;
}
在上述示例中,我们定义了 convertToSgamrTime
函数,它接受一个 std::chrono::system_clock::time_point
对象作为参数,并返回一个 sgamr::common::Time
对象。在转换函数中,我们提取了时间信息并构造了一个 sgamr::common::Time
对象,然后将其返回。
请注意,在实际使用时,你可能需要根据 sgamr::common::Time
类型的定义和要求来进行适当的转换和处理。
相关推荐

















