#include <iostream>
using namespace std;
class toCap
{
public :
virtual void conv_to_cap(char *)=0;//纯虚函数
};
class toCap_Impl: public toCap
{
public :
virtual void conv_to_cap(char *s)
{
if(s==0)
return;
int i = 0;
char c = s[i];
while (c)
{
if (c>='a'&&c<='z')
s[i]+='A'-'a';
c = s[++i]; //将小写变成大写
}
}
};
int main(void)
{
char s[] = "aBcdEFg_123f5\n";
toCap* tool = new toCap_Impl; //记住这个用法吧
puts(s);
tool->conv_to_cap(s);
puts(s);
return 0;
}
toCap* tool = new toCap_Impl; 这一步是什么意思?C++是不是有puts可以直接作输出用啊?这里用纯虚函数的意义是什么?谢谢