19.14
获得Screen::get_curor类型的成员函数指针,
pmf = &Screen::get是否合法,取决于其与get_curor的参数列表以及返回类型是否相同
19.15
需使用classname::*来说明当前真正是指向成员函数的指针,可以在指向成员函数的指针定义时加const限定符号,而函数指针是普通函数,不可以加
19.16
Sales_data& (Sales_data::*combineFunc)(Sales_data& data) = &Sales_data::combine;
19.17
using ScreenSet = Screen<int> & (Screen<int>::*)(char);
using ScreenMove = Screen<int> & (Screen<int>::*)(Screen<int>::pos r, Screen<int>::pos col);
using ScreenDisplay = Screen<int> & (Screen<int>::*)(ostream& os);
using ScreenGetWight = int & (Screen<int>::*)()const;
using ScreenGetContents = string & (Screen<int>::*)();
using ScreenGetHeight = int (Screen<int>::*)()const;
using ScreenSize = Screen<int>::pos()const;
19.18
略
19.19
略
19.20
嵌套类更改之后,需要将所有的QueryResult加上名字作用域即可,内容太多,不贴出
19.21
class Token{
public:
Token():tok(INT),ival(10){}
Token(const Token& t ):tok(t.tok){copyUniom(t);}
Token& operator=(const Token&);
~Token(){
if(tok == STR)
sval.~string();
}
Token& operator=(const string&);
Token& operator=(char);
Token& operator=(int);
Token& operator=(double);
private:
enum{INT,CHAR,DBL,STR} tok;
union {
char cval;
int ival;
double dval;
std::string sval;
};
void copyUniom(const Token&);
};
Token& Token::operator=(int i){
if(tok==STR){
sval.~string();
}
tok= INT;
ival = i;
return *this;
}
Token& Token::operator=(char c) {
if (tok == STR) {
sval.~string();
}
tok = CHAR;
cval = c;
return *this;
}
Token& Token::operator=(double d) {
if (tok == STR) {
sval.~string();
}
tok = DBL;
dval = d;
return *this;
}
Token& Token::operator=(const string& s) {
if (tok == STR) {
sval = s;
}else{
new (&sval)string(s);
}
tok = STR;
return *this;
}
void Token::copyUniom(const Token& t){
switch (t.tok)
{
case Token::INT:{
ival = t.ival;
break;
}
case Token::CHAR: {
cval = t.cval;
break;
}
case Token::DBL: {
dval = t.dval;
break;
}
case Token::STR: {
new(&sval)string(sval);
break;
}
default:
break;
}
}
Token& Token::operator=(const Token& t){
if(t.tok == STR && tok !=STR){
t.sval.~string();
}
if(t.tok == STR && tok == STR){
sval = t.sval ;
}else{
copyUniom(t);
}
tok = t.tok;
return *this;
}
19.22
略
19.23
Token& Token::operator=(const Token&& t) {
if (t.tok == STR && tok != STR) {
t.sval.~string();
}
if (t.tok == STR && tok == STR) {
sval = std::move(t.sval);
}
else {
copyUniom(t);
}
tok = t.tok;
return *this;
}
Token(const Token&& t) :tok(t.tok) { copyUniom(std::move(t)); }
19.24
执行赋值函数
19.25
Token& Token::operator=(int i){
if(tok==STR){
sval.~string();
}
tok= INT;
ival = i;
return *this;
}
Token& Token::operator=(char c) {
if (tok == STR) {
sval.~string();
}
tok = CHAR;
cval = c;
return *this;
}
Token& Token::operator=(double d) {
if (tok == STR) {
sval.~string();
}
tok = DBL;
dval = d;
return *this;
}
Token& Token::operator=(const string& s) {
if (tok == STR) {
sval = s;
}else{
new (&sval)string(s);
}
tok = STR;
return *this;
}
void Token::copyUniom(const Token& t){
switch (t.tok)
{
case Token::INT:{
ival = t.ival;
break;
}
case Token::CHAR: {
cval = t.cval;
break;
}
case Token::DBL: {
dval = t.dval;
break;
}
case Token::STR: {
new(&sval)string(sval);
break;
}
default:
break;
}
}
Token& Token::operator=(const Token& t){
if(t.tok == STR && tok !=STR){
t.sval.~string();
}
if(t.tok == STR && tok == STR){
sval = t.sval ;
}else{
copyUniom(t);
}
tok = t.tok;
return *this;
}
19.26
嵌套类更改之后,需要将所有的QueryResult加上名字作用域即可,内容太多,不贴出