编译器警告(等级3)c4996

qq_30818041 2015-11-01 05:56:18
#ifndef DAM_H_
#define DAM_H_
#include<iostream>
/*class baseDAM
{
private:
char * label;
int rating;


public:
baseDAM(const char *l = "null", int r = 0);
baseDAM(const baseDAM & rs);
virtual ~baseDAM();
baseDAM & operator=(const baseDAM & rs);
friend std::ostream & operator<<(std::ostream & os,const baseDAM & rs);

};
class lacksDAM :public baseDAM
{
private:
enum {
COL_LEN = 40
};
char color[COL_LEN];
public:
lacksDAM(const char * c = "blank", const char * l = "null",int r=0);
lacksDAM(const char * c, const baseDAM & rs);
friend std::ostream & operator <<(std::ostream & os, const lacksDAM & rs);

};
class hasDAM :public baseDAM
{
private:
char * style;
public:
hasDAM(const char * s = "none", const char * l = "null", int r = 0);
hasDAM(const char * s, const baseDAM & rs);
hasDAM(const hasDAM & hs);
~hasDAM();
hasDAM & operator=(const hasDAM & hs);
friend std::ostream & operator<<(std::ostream & os, const hasDAM & rs);
};
*/


class baseDAM
{
private:
char * label;
int rating;


public:
baseDAM(const char *l = "null", int r = 0);
baseDAM(const baseDAM & rs);
virtual ~baseDAM();
baseDAM & operator=(const baseDAM & rs);
friend std::ostream & operator<<(std::ostream & os, const baseDAM & rs);

};
class lacksDAM :public baseDAM
{
private:
enum {
COL_LEN = 40
};
char color[COL_LEN];
public:
lacksDAM(const char * c = "blank", const char * l = "null", int r = 0);
lacksDAM(const char * c, const baseDAM & rs);
friend std::ostream & operator <<(std::ostream & os, const lacksDAM & rs);

};
class hasDAM :public baseDAM
{
private:
char * style;
public:
hasDAM(const char * s = "none", const char * l = "null", int r = 0);
hasDAM(const char * s, const baseDAM & rs);
hasDAM(const hasDAM & hs);
~hasDAM();
hasDAM & operator=(const hasDAM & hs);
friend std::ostream & operator<<(std::ostream & os, const hasDAM & rs);
};
#endif



#include "dma.h"
#include<cstring>

/*baseDAM::baseDAM(const char * l, int r)
{
label = new char[std::strlen(l)+ 1];
std::strcpy(label, l);
rating = r;
}

baseDAM::baseDAM(const baseDAM & rs)
{
label = new char[std::strlen(rs.label) + 1];
std::strcpy(label, rs.label);
rating = rs.rating;
}

baseDAM::~baseDAM()
{
delete [] label;

}

baseDAM & baseDAM::operator=(const baseDAM & rs)
{
if (this == &rs)
return *this;
delete[]label;
label = new char[std::strlen(rs.label) + 1];
std::strcpy(label, rs.label);
rating = rs.rating;
return *this;


// TODO: 在此处插入 return 语句
}

std::ostream & operator<<(std::ostream & os, const baseDAM & rs)
{
os << "LAbel: " << rs.label << std::endl;
os << "Rating :" << rs.rating << std::endl;
return os;
// TODO: 在此处插入 return 语句
}

std::ostream & operator<<(std::ostream & os, const lacksDAM & ls)
{
os << (const baseDAM &)ls;
os << "color :" << ls.color << std::endl;
return os;
// TODO: 在此处插入 return 语句
}

std::ostream & operator<<(std::ostream & os, const hasDAM & hs)
{
os << (const baseDAM &)hs;

os << "style :" << hs.style<< std::endl;
return os;
// TODO: 在此处插入 return 语句
}

lacksDAM::lacksDAM(const char * c, const char * l = "null", int r):baseDAM(l,r)
{
std::strncpy(color, c, 39);
color[39] = '\0';
}

lacksDAM::lacksDAM(const char * c, const baseDAM & rs):baseDAM(rs)
{
std::strncpy(color, c, COL_LEN - 1);
color[COL_LEN - 1] = '\0';

}

hasDAM::hasDAM(const char * s, const char * l, int r): baseDAM(l,r)
{
style= new char[std::strlen(s) + 1];
std::strcpy(style, s);
}

hasDAM::hasDAM(const char * s, const baseDAM & rs)
:baseDAM(rs)
{
style = new char[std::strlen(s) + 1];
std::strcpy(style, s);

}

hasDAM::hasDAM(const hasDAM & hs):baseDAM(hs)
{
style = new char[std::strlen(hs.style) + 1];
std::strcpy(style, hs.style);
}

hasDAM::~hasDAM()
{
delete[] style;
}

hasDAM & hasDAM::operator=(const hasDAM & hs)
{
if (this == & hs)
return *this;
baseDAM::operator=(hs);
delete[] style;
style = new char[std::strlen(hs.style) + 1];
std::strcpy(style, hs.style);
return *this;


// TODO: 在此处插入 return 语句
}*/
baseDAM::baseDAM(const char * l, int r)
{
label = new char[std::strlen(l) + 1];
rating = r;
}
baseDAM::baseDAM(const baseDAM &rs)
{
label = new char[std::strlen(rs.label) + 1];
std::strcpy(label, rs.label);
rating = rs.rating;
}
baseDAM::~baseDAM()
{
delete[] label;
}
baseDAM & baseDAM::operator=(const baseDAM &rs)
{
if (this == &rs)
return *this;
delete[] label;
label = new char[std::strlen(rs.label) + 1];
std::strcpy(label, rs.label);
rating = rs.rating;
return *this;
}
std::ostream &operator<<(std::ostream &os, const baseDAM &rs)
{
os << "labelk :" << rs.label << std::endl;
os << " Rating :" << rs.rating << std::endl;
return os;
}
lacksDAM::lacksDAM(const char *c, const char *l, int r):baseDAM(l,r)
{
std::strncpy(color, c, 39);
color[39] = '\0';
}
lacksDAM::lacksDAM(const char *c, const baseDAM &rs)
:baseDAM(rs)
{
std::strncpy(color, c, COL_LEN - 1);
color[COL_LEN - 1] = '\0';

}
std::ostream& operator<<(std::ostream & os, const lacksDAM & ls)
{
os << (const baseDAM &)ls;
os << "color :" << ls.color << std::endl;
return os;
}
hasDAM::hasDAM(const char *s, const char *l, int r)
:baseDAM(l,r)
{
style = new char[std::strlen(s) + 1];
std::strcpy(style, s);
}
hasDAM::hasDAM(const char *s, const baseDAM &rs) : baseDAM(rs)
{
style = new char[std::strlen(s) + 1];
std::strcpy(style, s);
}

hasDAM::hasDAM(const hasDAM &hs):baseDAM(hs)
{
style = new char[std::strlen(hs.style) + 1];
std::strcpy(style, hs.style);
}
hasDAM::~hasDAM()
{
delete[] style;
}
hasDAM & hasDAM::operator=(const hasDAM & hs)
{
if (this == &hs)
return *this;
baseDAM::operator=(hs);
delete[] style;
style = new char[std::strlen(hs.style) + 1];
std::strcpy(style, hs.style);
return *this;
}
std::ostream & operator<<(std::ostream & os, const hasDAM & hs)
{
os << (const baseDAM)hs;
os << "style :" << hs.style << std::endl;
return os;
}




#include<iostream>
#include"dma.h"
int main()
{
using std::cout;
using std::endl;
using std::cin;
baseDAM shirt("portabelly", 8);
lacksDAM balloon("red", "bilmpo", 4);
hasDAM map("mercator", "buffalo keys", 5);
cout << "Displaying baseDAM objeo=ct :\n";
cout << shirt << endl;
cout << "Displaying lacksDAM objeo=ct :\n";
cout << balloon << endl;
cout << "Displaying hasDAM objeo=ct :\n";
cout << map << endl;
lacksDAM balloon2(balloon);
cout << "Result of lacksDAM copy:\n";
cout << balloon2 << endl;
hasDAM map2;
map2 = map;
cout << "Result of hasDAM copy:\n";
cout << map2<< endl;
cin.get();
return 0;
}
...全文
278 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_30818041 2015-11-09
  • 打赏
  • 举报
回复
引用 3 楼 赵4老师的回复:
#pragma warning(disable:4996)
...
谢谢我已经找到了,
赵4老师 2015-11-02
  • 打赏
  • 举报
回复
#pragma warning(disable:4996)
...
fefe82 2015-11-01
  • 打赏
  • 举报
回复
https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx
qq_30818041 2015-11-01
  • 打赏
  • 举报
回复
大家帮运行一下谢谢 用的 Blend for Visual Studio 2015编辑器

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧