代码:

#include <folly/concurrency/ConcurrentHashMap.h>
#include <string>
#include <iostream>

class Student {
public:
    Student(std::string name, int id, std::string email)
        : m_name(name), m_id(id), m_email(email)
    {}

    void printSelf() const {
        std::cout << "name: " << m_name << " "
            << "id: " << m_id << " "
            << "email: " << m_email << std::endl;
    }

private:
    std::string m_name;
    int m_id;
    std::string m_email;
};

int main() {
    folly::ConcurrentHashMap<std::string, Student> students;
    students.insert("Tom", Student("Tom", 1, "tom@gmail.com"));
    students.insert("Lilly", Student("Lilly", 2, "lilly@gmail.com"));

    for (const auto& st : students) {
        st.second.printSelf();
    }
}

 

编译:

g++ test.cpp -lfolly -lglog -ldl -ldouble-conversion -lpthread -lgflags -o students
$ ./students 
name: Tom id: 1 email: tom@gmail.com
name: Lilly id: 2 email: lilly@gmail.com

 

转自:

https://www.qingtingip.com/h_248421.html

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐