C++ 一种隐藏类成员变量的设计实现 TTS语音播报模块
前言
例如:c++类隐藏成员变量,通过基类暴露接口,供其他模块调用使用
本文,主要通过TTS语音播报模块介绍
提示:以下是本篇文章正文内容,下面案例可供参考
一、类的定义
基类CTTSBase:
#include <string>
class CTTSBase
{
public:
CTTSBase() {};
virtual ~CTTSBase() {};
virtual bool Speak(std::string)=0;
};
子类CTTSImpl.h:
#pragma once
#include "CTTSBase.h"
#include "sapi.h"
#include <list>
#include <string>
#include "sphelper.h"
#pragma comment(lib, "sapi.lib")
class CTTSImpl :
public CTTSBase
{
public:
CTTSImpl();
virtual ~CTTSImpl();
virtual bool Speak(std::string);
bool IsUseful();
private:
ISpVoice* m_pSpVoice = nullptr;
bool Init = false;
bool InitVoice();
void StopVoice();
};
子类CTTSImpl.cpp:
#include "pch.h"
#include "CTTSImpl.h"
#include "CWord