C++

c++代码学习

Posted by Roy Zhang on 2019-08-07

差不多都算完了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//如何使用explict
explicit ImageBuffer(size_t max_size = 30);
//在方程中使用const &的情况和override可以使编译器检查,其实问题不大尽量加override,还有final
void receive(const cv::Mat& image, double timestamp) override;
//容器std::pair的使用
virtual std::pair<double, cv::Mat> popLatest();
//使用shared_ptr
const std::shared_ptr<gim::camera::ImageBuffer>& image_buffer,
const gim::PinholeCameraModel& camera_model, const std::shared_ptr<gim::tracking::PointTransformer>& transformer,
const std::string& cfg_filename
//mutex lock_guard的使用
std::lock_guard<std::timed_mutex> lock(image_mtx_);
std::pair<double, cv::Mat>

//thread的使用方法
detector_thread_ = std::thread(std::bind(&YoloNode::runDetector, this));

const std::vector<std::pair<std::string, gim::Point3> >& list
//循环的快速使用方式auto&
for (const auto& pair : list)
{
if (pair.first == name)
{
return pair.second;
}
}

point.x = static_cast<float>(x);
//emplace_back和push_back的区别
attrs.emplace_back(name, itr->ValueStr());

for (const auto& add : extra_points_)
{
setAttribute(frame, add.first, add.second);
}

std::lock_guard<std::mutex> lock(buffer_mtx_);
//
constexpr double RAD_TO_DEG = 57.29579;
const auto& pos = target.pos();
//
std::vector<std::shared_ptr<gim::tracking::DetectionReceiver> > detection_receivers;
detection_buffer = std::make_shared<gim::tracking::DetectionFuser>(bucket_threshold, detection_fuse_threshold, min_cluster_size);
detection_receivers.push_back(detection_buffer);
// TODO
virtual ~Tracker() = default;
//
inline const std::shared_ptr<Tracker>& getTracker() const { return tracker_; }
//
std::make_pair(d, d_std);

在类建立之前就初始化值;