C++Primer 5th_GCC_4_7_19.rar

  • Z5_966539
    了解作者
  • 20.1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-28 06:56
    上传日期
c++primer第五版代码C++Primer 5th_GCC_4_7_0
C++Primer 5th_GCC_4_7_19.rar
  • 19
  • .useScreen.cc.swp
    16KB
  • Token.h
    4.1KB
  • out2
    417B
  • enum-match.cc
    2KB
  • Screen.cc
    1.5KB
  • bitfields.cc
    2.5KB
  • TextQuery.h
    3.8KB
  • typeid.cc
    1.7KB
  • enum.cc
    2.6KB
  • runpgms
    136B
  • calc.cc
    3.9KB
  • dyn_cast.cc
    2.8KB
  • makefile
    460B
  • Screen.h
    3KB
  • useScreen.cc
    3.8KB
  • README
    50B
  • tok2.cc
    1.6KB
  • memFN-bind.cc
    2KB
内容介绍
/* * This file contains code from "C++ Primer, Fifth Edition", by Stanley B. * Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the * copyright and warranty notices given in that book: * * "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo." * * * "The authors and publisher have taken care in the preparation of this book, * but make no expressed or implied warranty of any kind and assume no * responsibility for errors or omissions. No liability is assumed for * incidental or consequential damages in connection with or arising out of the * use of the information or programs contained herein." * * Permission is granted for this code to be used for educational purposes in * association with the book, given proper citation if and when posted or * reproduced.Any commercial use of this code requires the explicit written * permission of the publisher, Addison-Wesley Professional, a division of * Pearson Education, Inc. Send your request for permission, stating clearly * what code you would like to use, and in what specific way, to the following * address: * * Pearson Education, Inc. * Rights and Permissions Department * One Lake Street * Upper Saddle River, NJ 07458 * Fax: (201) 236-3290 */ #ifndef TOKEN_H #define TOKEN_H #include <string> using std::string; #include <iostream> #include "Token.h" class Token { friend std::ostream &operator<<(std::ostream&, const Token&); public: // copy control needed because our class has a union with a string member // defining the move constructor and move-assignment operator is left as an exercise Token(): tok(INT), ival{0} { } Token(const Token &t): tok(t.tok) { copyUnion(t); } Token &operator=(const Token&); // if the union holds a string, we must destroy it; see XREF(expldtor) ~Token() { if (tok == STR) sval.~string(); } // assignment operators to set the differing members of the union Token &operator=(const std::string&); Token &operator=(char); Token &operator=(int); Token &operator=(double); private: enum {INT, CHAR, DBL, STR} tok; // discriminant union { // anonymous union char cval; int ival; double dval; std::string sval; }; // each Token object has an unnamed member of this unnamed union type // check the discriminant and copy the union member as appropriate void copyUnion(const Token&); }; inline void Token::copyUnion(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; // to copy a string, construct it using placement new; see (XREF(placenew)) case Token::STR: new(&sval) std::string(t.sval); break; } } inline std::ostream &operator<<(std::ostream &os, const Token &t) { switch (t.tok) { case Token::INT: return os << t.ival; case Token::CHAR: return os << t.cval; case Token::DBL: return os << t.dval; case Token::STR: return os << t.sval; } } inline Token &Token::operator=(double d) { if (tok == STR) sval.~string(); // if we have a string, free it dval = d; tok = DBL; return *this; } inline Token &Token::operator=(char c) { if (tok == STR) sval.~string(); // if we have a string, free it cval = c; tok = CHAR; return *this; } inline Token &Token::operator=(int i) { if (tok == STR) sval.~string(); // if we have a string, free it ival = i; // assign to the appropriate member tok = INT; // update the discriminant return *this; } inline Token &Token::operator=(const std::string &s) { if (tok == STR) // if we already hold a string, just do an assignment sval = s; else new(&sval) std::string(s); // otherwise construct a string tok = STR; // update the discriminant return *this; } inline Token &Token::operator=(const Token &t) { // if this object holds a string and t doesn't, we have to free the old string if (tok == STR && t.tok != STR) sval.~string(); if (tok == STR && t.tok == STR) sval = t.sval; // no need to construct a new string else copyUnion(t); // will construct a string if t.tok is STR tok = t.tok; return *this; } #endif
评论
    相关推荐
    • C++ Primer
      C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。 对C++基本概念和技术全面而且权威的阐述,对...
    • c++课件
      c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件
    • C++ PRrimer
      本书是久负盛名的C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。本版对前一版进行了彻底的...
    • C++
      C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++
    • C++ primer
      本文档具有C++ primer 以及 C++ primer 标准答案各一份,内容清晰充实!希望与热爱C++的学友们一起同舟共济,努力学习!
    • C++ primer
      本书是久负盛名的C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。本版对前一版进行了彻底的...
    • c++yuyanbiancheng
      这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!
    • effective C++
      有关C++编程方面的检验性介绍,对由C转向C++,和有C++编程基础的程序员有帮助,不过是英文版
    • C++ Primer
      这本处适合各个阶段的C++程序员,这本书可以帮助初学者快速入门,里面有最实用,最容易理解的代码;同时这也是有经验的C++程序员最好的一本参考手册
    • C++ Primer
      本书是久负盛名的C++经典教程引,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++