1

C++ でソーシャル ネットワークのアカウント データベースのようなものを想像してみてください。各アカウントには、ユーザー名、レベル (管理者など)、このアカウントをフォローしているユーザーのリスト、およびこのアカウントにメッセージを送信したユーザーのリストがあります。

問題は、個別のユーザーごとに受信したメッセージの数をカウントしたいので、内部構造体の名前とカウントをリンクする必要があることです。

これは実装の良いアイデアですか?

    struct User {
        string name;
        int level;

        vector<string> followedBy;
        struct MessagedBy {
            string name;
            int count;
        };
    };

vector<User> users;
//@TODO vector of MessagedBy as an instance of User

vector of structs内にvector of structsを作成するにはどうすればよいですか? どうやってそれを指すのですか?

4

1 に答える 1

2

したがって、おそらく次のようなものが必要になるでしょう。

struct User {
        string name;
        int level;

    vector<string> followedBy;
    struct MessagedBy {
        string name;
        int count;
    };
    vector<MessageBy> messages;
};

その後、次を使用できます。

cout << "Messages from: " << users[index].messages[otherindex].name << ":" << users[index].messages[otherindex].count;
于 2013-03-21T16:35:05.573 に答える