《quantitative finance with cpp》阅读笔记26---设计一个接口并使用继承的方式重新调整chart类
作者:yunjinqi   类别:    日期:2024-01-02 18:54:17    阅读:440 次   消耗积分:0 分    

There is a lot of identical code between our different chart classes. In particular they all have in common a title and two functions called writeAsHTML. Design a base class and extend it for each chart. Draw a UML diagram of the resulting hierarchy. Use getter and setter methods to access the title.


写了一个BaseChart的接口,用于实现chart类的接口,在整合的过程中,又出现了报错:编译器错误 C2259,这个是继承的时候虚函数没有完全 实现导致的,一个个函数的名称,参数和返回值进行对比。


BaseChart.h

#pragma once
#include "stdafx.h"
#include "testing.h"

/*
There is a lot of identical code between our different chart classes. In
particular they all have in common a title and two functions called writeAsHTML. Design a base class and extend it for each chart. Draw a UML diagram
of the resulting hierarchy. 
 */
class BaseChart {
public:
    /*  Virtual destructor */
    virtual ~BaseChart() {};
    /*  Use getter and setter methods to access the title. */
    virtual void setTitle(const std::string &title) = 0;
    virtual std::string getTitle() = 0;
    /*  Calculate the payoff of the option given
        a history of prices */
    virtual void writeAsHTML(std::ostream& out) const=0;
    virtual void writeAsHTML(const std::string& file) const=0;
    //std::string title;
private:
    std::string title;
};


image.png

版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/391
上一篇:《quantitative finance with cpp》阅读笔记25---为Shape相关的类画出UML图
下一篇:蒙特卡洛模拟计算圆周率(python、java、cpp三个版本对比01)