Learn ft=rom WTL: CXXImpl<T>

// t9.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


class CRecordBase{
public:
    virtual ~CRecordBase()=0{}
    virtual CRecordBase* scale(float scale)=0;
};

template <class T>
class CRecordBaseT: public CRecordBase{
public:
    virtual CRecordBase* scale(float scale){
        T* ret(new T);
        ((T*)this)->scaleTo(scale, ret);
        return ret;
    }
};

class BRecord:public CRecordBaseT<BRecord>{
public:
    int scaleTo(float scale, BRecord* res){
        return 0;
    }

};

// CRecordBase <-- CRecordBaseT<> <-- BRecord

void main(){
    BRecord r;
    r.scale(1);
}

 

posted on 2018-04-19 17:34  cutepig  阅读(140)  评论(0编辑  收藏  举报

导航