CPP-基础:C++的new int()与new int[]
编写一个List类:
class List
{
int length; //列表长度
int* lpInt; //列表指针
List(int size);
~List();
}
List::List(int size)
{
length = size;
lpInt = new int(length); //关键点
int n;
for(n=;n<length;n++)
{
lpInt[n] = n;
}
} List::~List()
{
delete []lpInt; //出错,访问越界
}
在调试时,运行报错:
Debug Error!
Frogram: C:\Test\Debug\Test.exe
DAMAGE: after Normal block(#xxxx) at 0x00430040 (Press Retry to debug the application)
出错的原因:
lpInt = new int(length);
应该修改为:
lpInt = new int[length];
说明:
int* lpInt = new int(10)是分配一个int,也就是*lpInt = 10。
int* lpInt = new int[10]是分配10个int数组,lpInt是数组的首地址。
CPP-基础:C++的new int()与new int[]的更多相关文章
- CPP基础
CPP基础1. 如果没有指明访问限定符(public,private),class中默认的private,而struct中的成员默认是public的. #include <iostream> ...
- 【Go入门教程4】变量(var),常量(const),内置基础类型(Boolean、数值 byte,int,rune、字符串、错误类型),分组,iota枚举,array(数值),slice(切片),map(字典),make/new操作,零值
这小节我们将要介绍如何定义变量.常量.Go 内置类型以及 Go 程序设计中的一些技巧. 定义变量 Go 语言里面定义变量有多种方式. 使用 var 关键字是 Go 最基本的定义变量方式,与 C 语言不 ...
- python基础-基本数据类型总结_整型(int)_字符型(str)_day3
一.基本数据类型 1.整型(int) ps1:数字 int ,所有的功能,都放在int里a1 = 123a1 = 456 ps2: int 将字符串转换为数字 # -int # 将字符串转换为数字 ...
- C语言基础学习基本数据类型-int类型与int变量
int类型与int变量 针对不同的用途,C语言提供了多种整数类型.各种整数类型的区别在于所提供数值的范围,以及数值是否可以取负值. 在之前的实例中你已经看到过,int关键字用于声明整型变量. int类 ...
- Python基础学习Day3 数据类型的转换、int、str、bool、字符串的常用方法、for循环
一.数据类型的转换 常用的是:int 转str.str转int.int转bool 时 非零即为 True . # 数据类型之间转换 ***** # int <--> str str(i ...
- Python学习笔记之基础篇(三)python 数据类型 int str bool 详谈
python 的数据类型: 1.int:存放 1,2,3 等数据 ,用于数字的运算 2.bool :True, False 用于判断 3.str:字符串,用来存储少量的数据 4.list : 数组的 ...
- Java-集合-第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList(); l
第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; ...
- 第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList();
list.add(new Student("Tom", 18, 100, "class05")); list.add(new Student("Jer ...
- iOS NSInteger/NSUInteger与int/unsigned int、long/unsigned long之间的区别!
在iOS开发中经常使用NSInteger和NSUInteger,而在其他的类似于C++的语言中,我们经常使用的是int.unsigned int.我们知道iOS也可以使用g++编译器,那么它们之间是否 ...
- Mysql 中 int(3) 和 int(11) 的区别
[1]int(3) 和 int(11)的区别(思维惯性认知错误) 这里的3或11代表的是存储在数据库中的具体的长度,总以为int(3)只能存储3个长度的数字,int(11)只会存储11个长度的数字. ...
随机推荐
- Spring Boot + Vue 前后端分离开发,前端网络请求封装与配置
前端网络访问,主流方案就是 Ajax,Vue 也不例外,在 Vue2.0 之前,网络访问较多的采用 vue-resources,Vue2.0 之后,官方不再建议使用 vue-resources ,这个 ...
- 两个MATLAB在线工具,画图啥的都不用安装了
1. matlab网页版 http://octave-online.net/ http://www.compileonline.com/execute_matlab_online.php 2. 函 ...
- dos生成目录树
1. tree命令详解 [Tree命令作用] 以图形显示驱动器或路径的文件夹结构. [Tree命令格式] 在命令行窗口使用tree /?查看帮助. TREE [drive:][path] [/F] [ ...
- 黑马函数式接口学习 Stream流 函数式接口 Lambda表达式 方法引用
- Tinghua Data Mining 8
聚类 Clustering 根据评论信息做一些聚类,挖掘关系. bug 期望最大法 peek高峰的个数与高斯函数的个数不一定相同 Z隐含参数 不需要求 每个点属于哪个簇 类似于辅助线 跳板 借力 模型 ...
- SqlServer存储过程调用接口
因项目需求.需实现新增数据->触发器->存储过程->调用接口. https://blog.csdn.net/u010485134/article/details/58603370 另 ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- Hive_Hive的管理_web界面方式
端口:9999启动方式: hive --service hwi &通过浏览器访问:http://<IP地址>:9999/hwi/ 执行启动命令后,报错,找不到hive-hwi-*. ...
- centos安装openldap过程
1.下载软件如下,db是数据库 2.首先安装数据库db # tar xf db-4.8.30.tar.gz # cd db-4.8.30 # cd build_unix/ (# ../dist/con ...
- ZOJ Course Selection System DP
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5565 Course Selection System Time ...