开发者

Combining different datatypes into a void type

I am creating a search tree that would handle concatenated key. ie a key is a combination of multiple data types. For example key might be a concatenation of student_id,student_name,student_age...How should i c开发者_运维百科reate such a key when i pass these three values to create key function? Also given two keys how can i compare them?


Implementation of the comparison function is left as an excercise to the reader.

#include <cstdlib>
#include <string>
using namespace std;

class StudentKey 
{
public:
    string
        id_,
        name_;
    unsigned age_;

    bool operator<(const StudentKey& rhs) const;
};

StudentKey CreateKey(const std::string& student_name, const std::string& student_id, unsigned student_age)
{
    StudentKey ret;
    ret.name_ = student_name;
    ret.id_ = student_id;
    ret.age_ = student_age;
    return ret;
}

int main()
{
    StudentKey key = CreateKey("name","id",42);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜