warning: deprecated conversion from string constant to 'char*
warning: deprecated conversion from string constant to 'char*
#include<iostream>
using namespace std;
class Student
{
private:
int age;
char*name;
public:
Student(int m, char *n)
{
age=m;name=n;
}
Student()
{
age=;name="unnamed";
}
~ Student(){}
void SetMember ( int m,char *n )
{
age=m;name=n;
}
int Getage(){return age;}
char *Getname(){return name;}
};
int main()
{
Student stu[]={Student(,"wang"),Student(),Student()} ; stu[].SetMember(,"zhang"); cout<<stu[].Getage()<<","<<stu[].Getname()<<endl;
cout<<stu[].Getage()<<","<<stu[].Getname()<<endl;
cout<<stu[].Getage()<<","<<stu[].Getname()<<endl;
return ;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include<iostream>using namespace std;class Student {private: int age; const char*name;public: Student(int m, const char *n) { age=m; name=n; } Student() { age=0; name="unnamed"; } ~ Student() {} void SetMember ( int m,const char *n ) { age=m; name=n; } int Getage() { return age; } const char *Getname() { return name; }};int main() { Student stu[3]= {Student(13,"wang"),Student(),Student()} ; stu[2].SetMember(12,"zhang"); cout<<stu[0].Getage()<<","<<stu[0].Getname()<<endl; cout<<stu[1].Getage()<<","<<stu[1].Getname()<<endl; cout<<stu[2].Getage()<<","<<stu[2].Getname()<<endl; return 0;} |
看你的实现,传给Student类的字符串都是不可变的,都加上const就好了;否则你就要复制一份并且自己管理那块内存了。
warning: deprecated conversion from string constant to 'char*的更多相关文章
- deprecated conversion from string constant to ‘char*’
deprecated conversion from string constant to ‘char*’ #include <iostream> using namespace std; ...
- warning:deprecated conversion from string constant to 'char *' 解决方案
#include <iostream> using namespace std; int fuc(char *a) { cout << a << endl; } i ...
- warning:deprecated conversion from string constant to 'char *'
warning:deprecated conversion from string constant to 'char *' 解决方式 #include <iostream> using ...
- warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
在C++中, char* p = "abc"; // valid in C, invalid in C++ 会跳出警告:warning: ISO C++ forbids conve ...
- warning: ISO C++ forbids converting a string constant to 'char*'
第1种字符串赋值方式: char * fileName="./2017-09-02-10-34-10.xml";//这一种字符串赋值方式已经被ISO禁止了 第2种字符串赋值方式: ...
- ISO c++11 does not allow conversion from string literal to 'char*'
http://stackoverflow.com/questions/9650058/deprecated-conversion-from-string-literal-to-char
- 将string转换成char*
string 是c++标准库里面其中一个,封装了对字符串的操作 把string转换为char* 有3中方法: 1.data 如: string str="abc"; ch ...
- expected declaration specifiers or '...' before string constant
/work/platform_bus_dev_drv/led_dev.c:52: error: expected declaration specifiers or '...' before stri ...
- Constant Pool和String Constant Pool详解
Constant Pool常量池的概念: 在讲到String的一些特殊情况时,总会提到String Pool或者Constant Pool,但是我想很多人都不太明白Constant Pool到底是个怎 ...
随机推荐
- 廖雪峰Java11多线程编程-3高级concurrent包-3Condition
Condition实现等待和唤醒线程 java.util.locks.ReentrantLock用于替代synchronized加锁 synchronized可以使用wait和notify实现在条件不 ...
- sql.xml 循环插入与修改写法
// 插入 (交互一次数据库) <insert id="insertClient"> insert into m_linknodeclient (LinkClientI ...
- Spring boot配置Dubbo三种方式
方式一 使用注解的方式 导入dubbo-starter 在application.properties配置属性 使用@Service暴露服务 使用@Reference引用服务 使用@EnableDub ...
- 我王某的 低错&&(女装)Flag
日月共鉴,人心同睹. 喜欢你. 喜欢你的眼睛. 春天银河般闪烁的双瞳.春日阳光般温柔的眼神. 喜欢你的头发. 在微风中飘拂丝绢般柔滑的长发. 喜欢你的嘴唇. 给我甜蜜的吻.吐出忧伤叹息的嘴唇. 喜欢你 ...
- 19-10-28-A
竟然?竟然?竟然? 我已经用了半个键盘的编号了$\text{T_T}$ $\mathbb{AFO}$感稍强 h1是不是有点大? ZJ+TJ: T1 以为是什么数据结垢,但是是个链表. 所以可以使用 v ...
- STL 最大堆与最小堆
在第一场CCCC选拔赛上,有一关于系统调度的水题.利用优先队列很容易AC. // 由于比赛时花费了不少时间研究如何定义priority_queue的比较函数,决心把STL熟练掌握... Queue 首 ...
- 黑裙辉DS918+安装错误码21,安装教程 重装需要重新制作启动盘
不然报错误码21
- 运行第一个python程序,python 变量,常量,注释
一.运行第一个python程序: print('Hello,world') 保存为.py文件 在cmd窗口: python3x:python py文件路径 回车 python2x:python p ...
- 给java mongodb 官方driver 增加bean 操作
mongodb官方的java driver不支持直接插入java bean,只能使用DbObject的Key,Value形式进行insert,update,(c# mongodb官方driver类 ...
- linux使用wget
wget is a Linux command-line utility for retrieving files from the web, via HTTP, HTTPS and FTP prot ...