函数根据参数返回不同的对象?

时间:2014-12-05 19:30:05

标签: c++ qt

我有很多这样的函数:

void Business::convertDataToListEntityOfTypeX() // X = A,B,C.....

{

    QByteArray tmp = getData();
    bool ok;
    QVariantList result = parse (tmp,&ok);

    if (ok) {

        for (int i = 0; i < result.size(); ++i) {
            TypeXEntity e;

            convertVariantToTypeXEntity(result[i],e);
            typeXEntityList.push_back(e);//typeXEntityList are private variables in Business
        }
    }


}

我想将它们分组为一个像这样的函数

enum Type{TypeA, TypeB};
void Business::convertDataToListEntity(Type tp)

{

    QByteArray tmp = getData();
    bool ok;
    QVariantList result = parse (tmp,&ok);

    if (ok) {

        for (int i = 0; i < result.size(); ++i) {
            TypeXEntity e;// need a magic function map the enum with TypeXEntity

            convertVariantToTypeXEntity(result[i],e);
            typeXEntityList.push_back(e);//need a magic function map the enum with TypeXEntityList
        }
    }


}

那么有没有办法用QtBoost(Qt优先)做到这一点?

赞赏任何想法:)

0 个答案:

没有答案
相关问题