Blog Archive

Wednesday, October 31, 2018

c++ programming tutorial

http://www.newthinktank.com/2014/11/c-programming-tutorial/

C++中的虚函数的作用主要是实现了多态的机制。关于多态,简而言之就是用父类型别的指针指向其子类的实例,然后通过父类的指针调用实际子类的成员函数。这种技术可以让父类的指针有“多种形态”,这是一种泛型技术。所谓泛型技术,说白了就是试图使用不变的代码来实现可变的算法。比如:模板技术,RTTI技术,虚函数技术,要么是试图做到在编译时决议,要么试图做到运行时决议
---------------------
作者:haoel
来源:CSDN
原文:https://blog.csdn.net/haoel/article/details/1948051
版权声明:本文为博主原创文章,转载请附上博文链接!

代码:

#include <iostream>
using namespace std;

// Virtual Methods and Polymorphism
// Polymorpism allows you to treat subclasses as their superclass and yet
// call the correct overwritten methods in the subclass automatically

class Animal{
public:
void getFamily() { cout << "We are Animals" << endl; }

// When we define a method as virtual we know that Animal
// will be a base class that may have this method overwritten
virtual void getClass() { cout << "I'm an Animal" << endl; }
};

class Dog : public Animal{
public:
void getClass() { cout << "I'm a Dog" << endl; }

};

class GermanShepard : public Dog{
public:
void getClass() { cout << "I'm a German Shepard" << endl; }
void getDerived() { cout << "I'm an Animal and Dog" << endl; }

};

void whatClassAreYou(Animal *animal){
animal -> getClass();
}

int main(){

Animal *animal = new Animal;
Dog *dog = new Dog;

// If a method is marked virtual or not doesn't matter if we call the method
// directly from the object
animal->getClass();
dog->getClass();

// If getClass is not marked as virtual outside functions won't look for
// overwritten methods in subclasses however
whatClassAreYou(animal);
whatClassAreYou(dog);

Dog spot;
GermanShepard max;



// A base class can call derived class methods as long as they exist
// in the base class
Animal* ptrDog = &spot;
Animal* ptrGShepard = &max;

// Call the method not overwritten in the super class Animal
ptrDog -> getFamily();

// Since getClass was overwritten in Dog call the Dog version
ptrDog -> getClass();

// Call to the super class
ptrGShepard -> getFamily();

// Call to the overwritten GermanShepard version
ptrGShepard -> getClass();
        max.getDerived(); // OK
//ptrGShepard -> getDerived(); // error
GermanShepard* ptrGShepard2 = & max;
        ptrGShepard2 -> getDerived(); // OK
return 0;
}

Tuesday, October 30, 2018

c++中冒号(:)和双冒号(::)的用法

https://blog.csdn.net/zimingjushi/article/details/6549390


1.冒号(:)用法

(1)表示机构内位域的定义(即该变量占几个bit空间)

typedef struct _XXX{

unsigned char a:4; // 不明白如何使用

unsigned char c;

} ; XXX

(2)构造函数后面的冒号起分割作用,是类给成员变量赋值的方法,初始化列表,更适用于成员变量的常量const型。

struct _XXX{

_XXX() : y(0xc0) {}

};

(3) public:和private:后面的冒号,表示后面定义的所有成员都是公有或私有的,直到下一个"public:”或"private:”出现为止。"private:"为默认处理。

(4)类名冒号后面的是用来定义类的继承。

class 派生类名 : 继承方式 基类名

{

派生类的成员

};

继承方式:public、private和protected,默认处理,对struct 是public, 对class 是private
在struct继承中,如果没有显式给出继承类型,则默认的为public继承;
在class 继承中,如果没有显式给出继承类型,则默认的为private继承.

2.双冒号(::)用法

(1)表示“域操作符”
例:声明了一个类A,类A里声明了一个成员函数void f(),但没有在类的声明里给出f的定义,那么在类外定义f时,
就要写成void A::f(),表示这个f()函数是类A的成员函数。

(2)直接用在全局函数前,表示是全局函数
例:在VC里,你可以在调用API 函数里,在API函数名前加::

(3)表示引用成员函数及变量,作用域成员运算符

例:System::Math::Sqrt() 相当于System.Math.Sqrt()
——————————————————————————————————————

VC中如下

::是C++里的“作用域分解运算符”。比如声明了一个类A,类A里声明了一个成员函数voidf(),但没有在类的声明里给出f的定义,那么在类外定义f时,就要写成voidA::f(),表示这个f()函数是类A的成员函数。
  :: 一般还有一种用法,就是直接用在全局函数前,表示是全局函数。当类的成员函数跟类外的一个全局函数同名时,考试,大提示在类内定义的时候,打此函数名默认调用的是本身的成员函数;如果要调用同名的全局函数时,就必须打上::以示区别。比如在VC里,你可以在调用API函数时,在API函数名前加::。(编辑:)







*********************************************************************************************

*********************************************************************************************

*********************************************************************************************

这篇文章将总结C/C++中的冒号的用法。

1、位域定义
这个在前面关于位结构体的文章里说得够多的了,不再重复了。

2、类构造函数(Constructor)的初始化列表
先说下什么叫构造函数吧(是不是啰嗦了?C++的人应该都知道了吧,还是以防万一一下)。所谓构造函数,就是与类同名的函数,它与普通函数的区别在于,它没有返回类型。
在构造函数后面紧跟着冒号加初始化列表,各初始化变量之间以逗号(,)隔开。下面举个例子。
class myClass
{
public :
myClass();// 构造函数,无返回类型,可以有参数列表,这里省去
~myClass();// 析构函数
int a;
const int b;
}

myClass::myClass():a(1),b(1)// 初始化列表
{
}
上面的例子展示了冒号的这个用法,下面对这个用法进行几点说明:
1)初始化列表的作用相当于在构造函数内进行相应成员变量的赋值,但两者是有差别的。
在初始化列表中是对变量进行初始化,而在构造函数内是进行赋值操作。两都的差别在对于像const类型数据的操作上表现得尤为明显。我们知道,const类型的变量必须在定义时进行初始化,而不能对const型的变量进行赋值,因此const类型的成员变量只能(而且必须)在初始化列表中进行初始化,即下面的代码将会出错:
myClass::myClass()
{
a = 1;// 没错,效果相当于在初始化列表中进行初始化
b = 1;// 出错,const变量不能进行赋值操作;
}
2)初始化的顺序与成员变量声名的顺序相同。
先看一下下面的程序:
myClass::myClass():b(1),a(b)
{
}
这样的执行结果a,b各是多少呢?b=1,a=1?不是,b=1而a是个随机数。这一点是相当重要的哦,一般在初始化列表中进行初始化时,初始化的顺序应与声明的顺序保持一致,防止出现不必要的错误。
3)对于继承的类来说,在初始化列表中也可以进行基类的初始化,初始化的顺序是先基类初始化,然后再根据该类自己的变量的声明顺序进行初始化。

3、声明基类。
假设我们重新定义一个类,继承自myClass类。定义方式如下:
class derivedClass : public myClass
{
// 略去
}
这里的冒号起到的就是声名基类的作用,在基类类名前面可以加public/private/protected等标签,用于标识继承的类型,也可以省略,省略的话,用class定义的类默认为private,用struct定义的类默认为public,至于具体各个标签有什么区别这里就不说了。
与初始化列表一样的,这里也可以声名多个基类,各基类之间用逗号(,)隔开。

4、条件语句(? :)
与?构成条件语句,作用相当于if else,如下;
int a,b,c;
a=3;
b=2;
c=a>b?a:b;// 如果a>b成立,则反a赋给c,否则把b赋给c
条件语句的结构为:
条件表达式?表达式1:表达式2
当条件表达式为true时,表达式的值为表达式1的值,否则为表达式2的值。
几点说明:
1)?:可以嵌套,但不推荐使用(难懂),下面的表达式你能看懂啥意思不?
int max = i>j ? i>k ? i : k : j>k ? j : k;
脑袋大了吧,呵呵。
2)?:具有很低的优先级,这个要注意哦,下面的程序执行结果是啥呢?
int i = 3;
int j = 2;
cout << i>j?i:j;// 出错,<<比>具有更高的优先级,执行顺序为 ((cout<<i)>j)?i:j,相当于是比较cout<<i与j的大小,然后根据比较结果决定表达式值为i或j,这显然要出错的,cout<<i的值是cout,不能跟整型数j进行比较。
cout << (i>j)?i:j;//输出1或0,相当于(cout<<(i>j))作为判决条件,来决定表达式的值为i或j,而cout<<(i>j),i>j则输出1否则0,然后再将(cout<<(i>j))作为?:的条件,如果cout正确执行则为1(true),否则为0(false),以此决定表达式值为i或j
cout <<(i>j?i:j);//i>j则输出i,否则输出j,表达式值为true如果cout正确执行,否则为false
更多的关于优先级的问题就不说了。

5、语句标签
通常跟goto配合使用,如:
step1: a = f1();
....
goto step1;
这种作法也不是很推荐,原因在于它破坏了语句的顺序执行,这样的代价大家应该清楚吧。不过存在即为合理嘛,既然它还存在,肯定还是有它的用处有它的好处的,比如说,多层嵌套的退出(会比break continue直观一点吧),也可以避免重复代码之类之类的

6、switch语句中case后。
这个不说了,要是不会的话,我也没话可说了。

7、汇编指令模板
这个我也不懂,不班门弄斧了,可以参考一下:http://developer.e800.com.cn/articles/2006/43/1144846933898_1.html
改天学习一下。

Tuesday, October 23, 2018

音视频及FFMpeg概念篇

音视频编解码概念
音视频格式有很多种,我们所熟知的音频文件有wav、mp3等 ,视频格式有mp4、3gp、rmvb、avi、mov等等。这些格式并不是只是文件的后缀不同,而是文件中的内容有很大的不同,哪怕这个媒体文件播放起来我们看起来觉得它们是一模一样的。
另外,我们看到的电影或者视频片段,它往往是由两个或者两个以上的流组成的,比如声音流、视频流、字幕等。甚至声音也有左声道、右声道什么的。
那么这些东西是怎么串联的呢?编码、解码、混流、解复用、过滤器这些都是些啥?为啥要有这些步骤?

编解码
我们应该都熟悉RGBA的色彩,用红绿蓝再加上透明度可以组成我们人眼可见的各种色彩,但是实际上许多色彩的差异并不是那么明显,就算肉眼去很仔细的比对都不能分辨出来。而通常视频依照24帧每秒的频率存储图像、甚至以30帧每秒的频率存储图像,如果以rgba的格式存储,占用的存储空间是非常庞大的,而且不利于网络传输。而YUV格式,如果一帧RGBA的图像数据占用16份,那么RGB占用12份,而YUV420只占用6份。虽然RGB的图像变为YUV格式质量通常会有损失,但是这个损失通常是可以接受的。
虽然转换成YUV格式,可以节省一些存储空间,但是情况依旧不容乐观。人们又发现对于连续的视频而言,通常连续的帧之间,图像之间存在大量重复的数据,这样,就可以在存储的时候把重复的数据去掉,再需要展示的时候再恢复出来,这样就可以大大节省存储空间,网络传输的之后,也同样把大量重复的去掉,接收端播放的实话再恢复,以达到节省带宽,加快传输速度的目的。这个去除大量重复数据的过程我们可以理解为音视频的编码,把去除的数据恢复回来的过程,我们可以理解为音视频的解码,也就是Codec。

混流、解复用
混流也就是复用,或许更为标准的叫法应该是复用。混流是什么?上面说了,我们看到的视频通常有图像又有声音,这些声音和图像的数据通常是两条不同的流,把这两条流混合在一起的过程就是混流。那么反之,把混合在一起的音视频拆分成各自的音频流、视频流的过程就是解复用。编解码的目的很明确,那么混流和解复用的目的又是什么呢?拿网络传输来说,在线观看视频,总不能先把声音传过去再传图像,或者说先把所有的图像传过去再传声音,而是传一点图像就传一点声音,这就是混流了,也就时Mux,与之对应的就是解复用Demux.

过滤器
我总是觉得这个翻译,对于Filter来说并不好听,我更喜欢翻译它为滤镜,更确切的说,应该可以把它理解为处理器。它并不是真的就是用来过滤,像把浑浊的水过滤成清水那样。比如我们给视频图像加个水印,或者改变视频的声音,让声音变得尖锐或者低沉等等,这些就是滤镜的工作了。

音视频编解码方式
简单的来分,我们可以把音视频的编解码分为软编解码和硬编解码,这里的软就是指软件,硬就是指硬件。所谓的软编解码,就是依赖软件,利用CPU进行编解码。而硬编解码可以理解为使用非CPU进行编解码,更准确的是,依赖音视频编解码模块进行音视频编解码。至于使用时到底是使用硬编解码还是软编解码,还是要依赖需求,根据它们各自的特点进行选择。
通常来说,软编解码实现直接简单,参数调整方便,支持格式广泛,编码视频质量相对硬编码更为清晰。但是软编解码相对硬编解码性能略差,会给CPU带来较重负载。
以Android平台为例,Android硬编解码MediaCodec从Android4.1才开始支持,混流用的MediaMuxer到Android4.3才开始支持。在Android4.1以前,如果开发者想要做视频相关应用通常会选择FFMpeg之类的开源编解码框架进行软编解码。当然,FFMpeg也可以配置选择使用硬编码。一般来说,如果应用只需要支持Android 4.3及以上,只需要做录制视频、播放Mp4文件,硬编解码方案优于软编解码方案。但是如果应用需要支持4.1以前的系统,或者要求支持其他音视频格式,比如rmvb之类的,可能就不得不使用软编方案了。

FFMpeg
上面提到了FFMpeg,那么FFMpeg又是什么呢?从其官网上可以知道,FFMpeg是一个全球领先的多媒体开源框架,用于音视频的编解码、混流、解复用、过滤器、转码以及播放等。它支持多平台、多种音视频格式。而且它便于移植及二次开发,当前有很多软件都用到了FFMpeg。FFMpeg 既有可以直接使用的工具,也有可以供开发人员使用的库。
其工具有:

ffmpeg:一个用于多媒体格式转换的命令行工具
ffserver: 一个用于现场直播的多媒体流服务器
ffplay: 一个基于SDL和FFMpeg库的简单的媒体播放器
ffprobe:一个简单的多媒体分析工具
其开发库有:

libavutil: 包含简化编程功能的库,包括随机数生成器、数据结构、数学相关的程序、核心多媒体框架等等。
libavcodec:包含用于音视频编解码的编码器和解码器的库。
libavformat: 包含多媒体容器格式的解码器和多路复用器的库。
libavdevice: 包含输入输出设备的库,用于从许多常见的多媒体输入输出软件框架中获取和渲染,包括Video4Linux、Video4Linux2、VfW和ALSA。
libavfilter:一个包含媒体过滤器的库。
libswscale:一个执行高度优化的图像缩放和色彩空间/像素格式转换的库。
libswresample:一个执行高度优化的音频重采样、再分频和采样格式转换操作的库。
值得注意的是,FFMpeg并不是直接就可以用于各种视频的编解码工作,它只是一个框架。真正执行编解码工作的通常会用到其它编解码器。比如进行h264的编码,一般会选择FFMpeg配合x264进行使用。
---------------------
作者:湖广午王
来源:CSDN
原文:https://blog.csdn.net/junzia/article/details/78167605
版权声明:本文为博主原创文章,转载请附上博文链接!
reference:
https://blog.csdn.net/zhuweigangzwg/article/details/72481966
https://blog.csdn.net/zhuweigangzwg/article/details/72624857

Wednesday, October 3, 2018

How To Measure Customer Emotions


Measuring customer emotions for your Customer Experience is a vital activity for your organization. After all, if you can’t measure it, you can’t manage it, as the saying goes.
We discussed how to measure customer emotions on our recent podcast. Today we will discuss how to measure feelings, which feelings you should measure, and where and when you should measure them.
How Do We Measure a Feeling?
The most common way to measure emotion is the Net Promoter Score (NPS). Effectively, NPS estimates how likely a customer is to recommend your product or service to their friends and family. The scale is 1-10. If you score a 6 or under, you are a detractor. A 7 or 8 score is considered passive. If you have 9 or 10, you are a promoter. Your most loyal customers are promoters and have high NPS scores. To get the Net in the Net Promoter Score, you subtract your promoters from your detractors. The remaining number is your NPS.
I like NPS because it’s a simple way to measure. Everyone can understand it. Another reason I support it is that you can compare yourself to other organizations in a way that compares apples to apples, as it were. Also, I appreciate that it talks about a recommendation, which encapsulates the emotional aspects of a Customer Experience.
For example, let’s say I was traveling to your hometown and I asked you for a restaurant recommendation while I was there. You would tell me your favorite (or maybe favorites). For those restaurants, you are a promoter. The reason you promote it is your own, but it is likely because of the way they make you feel, e.g., fat and happy, as one of my team members likes to say!
However, remember that no way of measuring is perfect. Even NPS.
As I said about NPS, there are things I like about it. It is easy to understand and it helps you compare to other organizations. It is also an effective way to measure customer feeling.
What NPS lacks is that it isn't comprehensive or specific enough for me. It also does not tell you why people would or would not recommend you. Information like that requires more than an NPS assessment. If you have a slipping NPS, the score itself will not tell you what you need to do to change it or what you need to improve upon to turn around the decline in rating.
What Emotions Should You Measure?
NPS is a meaningful way to measure your Customer Experience, but it isn't the only way. It should be only part of how you measure customer emotions. Another part of the whole exercise to gauge feelings is first to define what emotion you are trying to evoke from your customers. Whatever emotion you choose, it should be one that drives value (e.g., revenue, profits or $$$$) for your organization.
Examples of this type of definition could be:
●      We want customers to feel cared for at our community financial institution.
●      We want customers to feel safe and protected with our identity protection app.
●      We want customers to feel relaxed after attending our day spa.
And so on…whatever emotion may be appropriate for a customer to feel in your particular business or industry.
(If you want help finding the right emotion, we recommend looking at our Emotional Signature overview and the Hierarchy of Emotions we developed to support it.)
Where and When Should You Be Measuring Them?
Once you have defined what emotion you wish to evoke, you should then be measuring how you are doing toward that goal. This process is not complicated. Mostly, you just ask customers.
In our global Customer Experience Consultancy, we recommend asking your customers often about how they feel. We believe in questioning at the transactional stage, like at the end of a call center interaction or a chat exchange. We also recommend following up with customers at a different time, too. By that, I mean with a customer survey in the mail or online, etc.
However, the questions should ask about the specific emotion you seek to evoke.
Examples of that data gathering could be:
●      Customer, do you feel cared for after working with us?
●      Customer, do you feel safe and protected when using our product?
●      Customer, do you feel relaxed as a result of your interaction with us?
(These are goofy, I know, but the point is that you are following up on the emotion you sought to evoke.)
One point of clarification here: you can’t ask a customer about an experience they had some time ago and expect to get accurate data. For example, you can’t ask a customer how they felt dining at a restaurant six months ago. They might not remember eating there anymore. The follow-up should happen within a short amount of time of the experience, so customers remember how they felt.
My Wisdom on Measuring Emotions
What happens, usually, is organizations have measurements of rational stuff, like how quickly your call is answered and the efficiency of the delivery. What they don’t have is the emotional measures. That’s where you can really miss out for Customer Experience success.
To be clear, however, rational vs. emotional measurement is not an either/or proposition. You should measure rational things and irrational things. Both are crucial to improving your Customer Experience.
There is no one way to measure emotions. The examples I have given are the ways I often use but are by no means exhaustive.
I believe a deliberate effort to evoke a particular emotion that drives value for your organization and then following up on whether you are achieving that is essential to your success. It will give you a deeper understanding of how your Customer Experience makes your customers feel—and what you are doing to make them feel that way.
Hear the rest of the conversation on “How to Measure Customer Emotions”on The Intuitive Customer Podcast. These informative podcasts are designed to expand on the psychological ideas behind understanding customer behavior. To listen in, please click here.


If you enjoyed this post, you might be interested in the following blogs and podcasts:
Colin Shaw is the founder and CEO of Beyond Philosophy, one of the world’s leading Customer experience consultancy & training organizations. Colin is an international author of six bestselling books and an engaging keynote speaker.
Follow Colin Shaw on Twitter @ColinShaw_CX
Link:
https://www.linkedin.com/pulse/how-measure-customer-emotions-colin-shaw-1f/?trk=eml-email_feed_ecosystem_digest_01-recommended_articles-13-Unknown&midToken=AQGlv4VljRf0Fw&fromEmail=fromEmail&ut=3ROJO7ubSPhUs1