Professional C++ 01 A Crash Course in C++ 快速的C++基础知识复习

该章节回顾了C++的基础知识,包括空间命名规则、变量定义与操作符、循环语句、枚举类型等内容,并通过一个管理员工系统的例子进行实践应用。
摘要由CSDN通过智能技术生成

本章节主要是对C++基础知识的回顾,不会涉及太简单的知识点,比如=和==的区别,也不会涉及太复杂的知识,比如volatile关键字的作用。

(1) 空间命名规则

#ifndef NAMESPACE_H
#define NAMESPACE_H
// namespaces.h
namespace mycode {
    void foo();
}
#endif // NAMESPACE_H

#include "namespace.h"
#include <iostream>

void mycode::foo()
{
    std::cout << "foo() called in the mycode namespace" << std::endl;
}

#include "namespace.h"

using namespace std;
using namespace mycode;

int main(int argc, char *argv[])
{
    foo();
}

output:

foo() called in the mycode namespace

(2) 变量的定义, 操作符,循环语句全部都是基础知识。

(3) 枚举类型

typedef enum { kPieceTypeKing, kPieceTypeQueen, kPieceTypeRook,
	kPieceTypePawm
} PieceT;

(4) Stack 和 Heap的区别

stack分配的空间一般都是程序自动管理,heap用于new分配,delete删除。

(5)综合举例,一个管理员工系统

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
// employee.h
#include <iostream>
namespace Records {
    const int kDefaultStartingSalary = 30000;

    class Employee {
    public:
        Employee();
        void promote(int inRaiseAmount = 1000);
        void demote(int inDemeritAmount = 1000);
        void hire();
        void fire();
        void display();

        void setFirstName(std::string inFirstName);
        std::string getFirstName();
        void setLastName(std::string inLastName);
        std::string  getLastName();
        void setEmployeeNumber(int inEmployeeNumber);
        int getEmployeeNumber();
        void se
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Author: Josh Lospinoso Pub Date: 2019 ISBN: 978-1593278885 Pages: 792 Language: English Format: PDF Size: 10 Mb A fast-paced, thorough introduction to modern C++ written for experienced programmers. After reading C++ Crash Course, you’ll be proficient in the core language concepts, the C++ Standard Library, and the Boost Libraries. C++ is one of the most widely used languages for real-world software. In the hands of a knowledgeable programmer, C++ can produce small, efficient, and readable code that any programmer would be proud of. Designed for intermediate to advanced programmers, C++ Crash Course cuts through the weeds to get you straight to the core of C++17, the most modern revision of the ISO standard. Part 1 covers the core of the C++ language, where you’ll learn about everything from types and functions, to the object life cycle and expressions. Part 2 introduces you to the C++ Standard Library and Boost Libraries, where you’ll learn about all of the high-quality, fully-featured facilities available to you. You’ll cover special utility classes, data structures, and algorithms, and learn how to manipulate file systems and build high-performance programs that communicate over networks. You’ll learn all the major features of modern C++, including: Fundamental types, reference types, and user-defined types The object lifecycle including storage duration, memory management, exceptions, call stacks, and the RAII paradigm Compile-time polymorphism with templates and run-time polymorphism with virtual classes Advanced expressions, statements, and functions Smart pointers, data structures, dates and times, numerics, and probability/statistics facilities Containers, iterators, strings, and algorithms Streams and files, concurrency, networking, and application development With well over 500 code samples and nearly 100 exercises, C++ Crash Course is sure to help you build a strong C++ foundation.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值