编译器警告(等级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;
}