编译器警告(等级3)c4996
#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;
}
#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;
}
...全文
相关推荐
VS2019升级VS2022编译错误解决[源码]
解决方案三通过修改项目级编译器设置,将C4996警告等级由Error降级为Warning或Disabled,可在“配置属性→C/C++→常规→SDL检查”与“C/C++→高级→将特定警告视为错误”中分别调整
error C4996
"在使用Visual Studio 2012进行C或C++编程时,可能会遇到编译错误‘error C4996’,提示‘fopen’函数可能不安全,建议使用fopen_s代替。这个错误是由于Micros
vs2012 error c4996: This function or variable may be unsafe
因此,编译器通过C4996错误提示开发者考虑使用`fopen_s`函数替代,后者在操作时会进行更多的检查和验证以确保安全。
VS关警报预处理命令行
在探讨“VS关警报预处理命令行”这一主题时,我们主要关注的是如何在Visual Studio 2013(简称VS2013)环境中处理C语言编程中由`scanf`函数引发的编译器警告。
Visual Studio Community 2015 – _CRT_SECURE_NO_WARNINGS
"在Visual Studio Community 2015中,当你使用某些标准库函数如`scanf`, `strtok`, `fopen`等时,编译器可能会发出C4996警告,提示这些函数可能存在安


