博客
关于我
C++面向对象 class four
阅读量:577 次
发布时间:2019-03-11

本文共 1277 字,大约阅读时间需要 4 分钟。

  • 类的组合,注意对对象成员的初始化要用成员初始化列表。
  • 利用拷贝构造函数初始化组合类的时候注意对象成员要有拷贝构造函数,牵扯深拷贝与浅拷贝。
  • 深拷贝与浅拷贝区别:主要体现在使用指针时,深拷贝(自己实现)申请新内存,浅拷贝没有申请新内存。
  • C++多文件操作。
  • 继承开头。
#ifndef COMPUTER_H_INCLUDED#define COMPUTER_H_INCLUDED#include
#include
#include
#include "CPU.h"#include "Memory.h"#include
using namespace std;class Computer{ public://在组合类中,成员初始化列表的调用顺序不影响构造函数的调用顺序 Computer(string brand,double fre,int cap):cpu(brand,fre),mem(cap){ //不能在构造函数里面初始化对象成员,用成员初始化列表 cout<<"A computer is created."<
#ifndef CPU_H_INCLUDED#define CPU_H_INCLUDED#include
#include
#include
#include
using namespace std;class CPU{ public: CPU(string s = " ",double p = 0) { brand = s; main_fre = p; cout<<"The CPU "<
<<" is created"<
#include
#include
#include
#include
using namespace std;class Person{ public: Person(char _name[],int _age){ name = new char[strlen(_name)+1]; strcpy(name,_name); age = _age; } ~Person(){ delete[] name; } void setName(char _name[]){ // delete[] name;// name = new char[strlen(_name)+1]; strcpy(name,_name); } void show() { cout<
<<' '<
<

转载地址:http://vvlvz.baihongyu.com/

你可能感兴趣的文章
MySQL5.6忘记root密码(win平台)
查看>>
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
mysql5.7性能调优my.ini
查看>>
mysql5.7的安装和Navicat的安装
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump备份时忽略某些表
查看>>
mysqlreport分析工具详解
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>
MYSQL一直显示正在启动
查看>>
MySQL一站到底!华为首发MySQL进阶宝典,基础+优化+源码+架构+实战五飞
查看>>
MySQL万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>