编译器警告(等级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;
}
...全文
244 4 打赏 收藏 转发到动态 举报
写回复
用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编辑器
1、 QAC介绍和使用说明 其他的功能概括 1、提供一种可量化措施的代码度量值属性:33基于功能 32基于文件和4个项目级别 2、功能结构关系图,以提供控制流动洞察 3、展示全局调用函数的关系图引用和文件树结构 4、提供统计分析对代码质量的全面评估 5、跨模块分析能力(CMA)、分析递归功能和全局标识符的各种问题 6、简化的旧代码修改的设置基准模块 Source..c文件通过分析工具生成3种文件source.c.i、source.c.met、source.c.err。source.c.i文件可以直接生成报告文件,.met、.err这两个文件可以分析出功能结构、关系、特征标准、报告或者进行跨模块分析,对于跨模块分析和剖析器分析需要进行配置,source.c.met、source.c.err、配置文件可以在信息浏览器中显示 2、 规划 2.1、自动生成文件及参数说明 生成自动文档步骤: 1、从文件菜单中选者Auto-Create Project 2、进入Root Folder Name,这是工程的根目录,后面的自动生成的文件都会对应此根目录产生 3、进入Starting Directory,这个源代码目录与工程的根目录相连 4、进入Output File Path,这里可以选择QAC分析后的输出文件,好的情况就是用一个专门的目录和工程根目录相连 5、Replicate source tree structure in output paths通常是为输出部分建立一个子目录结构,这里可以有2种选择,可以选择Parallel to Source Structure为源代码建立一个平行的目录结构,或者选择Sub-path to each source location把规定的输出的子目录嵌入到源工程目录下面 6、选择File Extensions可以加入项目,通常只要选择一个.C文件,包括对.H文件也就被加入 7、为文件夹选择一个个性,可能会使用默认设置为起始点,可以在QAC中选择Configuration菜单 8、点击OK就是建立了工程,包含源文件工程和子文件夹 9、保存文件,外部扩展名为.prj 注意:也可以在已有的项目上自动生成一个文件夹,点击菜单Edit > Auto-create Sub-Folders,其余步骤和以上相同 文件夹参数:包括文件夹名称、默认源路径、输出路径和三种个性 可以进入Edit > Folder Parameters只可以改变文件夹参数,进入Edit > Propagate Changes to Sub-Folders可以改变所有子文件夹参数 2.2、手动生成文档及参数说明 生成手动文档步骤: 1、从菜单File中选择New Project,显示一个对话框New Project Parameters 2、进入Root Folder Name,输入一个项目名称 3、进入Default Source Path为项目初始化文件夹,这个路径可以改变所有子文件夹 4、在Output File Path中选择需要输出的分析文档 5、为工程选个个性 6、点击 OK创建项目,这工程的配置是唯一的文件夹 7、按要求增加更多的子文件夹和文件按要求 8、保存文件,外部扩展名为.prj 文件夹参数;在File > Reopen这项中可以有10多个选项,当没用的文件可以选择Clean-up。 文件和目录的位置时重新打开项目,将检查的存在。如果不存在一个条目将显示下面的对话框。有的更正可以自动应用的过程。 2.3、选择输出文件 一般文件夹的层次结构在在左边显示,选择的列表在文件的右边显示 所有的选择都在Browse 和d Reports这两个菜单中 A、如果选择单个文件或一组文件,则使用 B、否则当前所选文件夹,再加上所有子其文件夹,窗体所选内容。这意味着使用这些文件夹中的所有文件。 在浏览器内修改,有可能会改变开始的选择,用Select Files…在File菜单内 2.4、互相比较和环境变化的报告 2.4.1、根路径 2.4.2、基于GUI的环境变量创建 2.4.3、相对路径和环境变量的运用 选择Apply Relative Paths项可以选择相对路径减少的所有文件条目,根目录在右上角,表示保存项目文件的位置,确定路径是否合适相对路径减少。 选择Make file paths in each folder relative to its Default Source Path entry项,如果想要应用一个虚拟的环境变量表达默认每个文件的源路径到其他文件条目下。 在Available Environment Variables列表下,可以添加EVs to Apply至右边框中,将这种替换只发生在项目中的项的文件或关联的路径不受相对路径减少的个性 选择Apply path reduction to personality file entries associated with the project项,为了继续应用相对路径和环境变量在文件路径下的个性定义 选择Remove all path reduction from the project and associated personalities项若要撤消所有的相对路径和环境变量从相关个性设置项目恢复到完全在所有情况下限定的路径 例如,一个被重建的“Diff”项目如下所示与充分的relative道路实施 3、 配置QAC 为应用程序配置主要通过可访问Configuration > Options选项卡,有以下几点: Annotated Source 附加说明源 Cross-Module Analysis 跨模块分析 Custom Reports 自定义报告 Default Personalities 默认特性 Editor Preferences 编辑选项 Environment 环境 (Product)Extensions (产品)条目 Project File Options 项目文件选择 要查看您的安装与那些一起中的个性的一组在您的项目中定义,可以在Configuration下选择Message Personalities, Analyser Personalities or Compiler Personalities这几个选项 当创建了一个额外的特性,也可以设置它们成为系统默认,在Configuration>Options>Default Personalities下设置 3.1、配置编译器特性 看附录A 3.1.1、设置系统头文件 在系统包括系统标题选项卡上的标题,设置您系统标头包含路径 可以点击Suppress Output阻止这些头文件,当阻止了那些头文件,一些从特定的头文件或路径中产生的分析数据也不能在.err、.met文件中出现 您可以手动输入是相对于当前项目的路径位置,虽然建议进行完整路径选择和然后将任何选择的道路减少保存项目的过程中的应用操作 3.1.2、设置系统宏 在System Macro Defines下的Project Macros菜单中,设置宏同编译器或开发环境一致,宏可以在Compiler Personality或Analyser Personality设置 3.1.3、设置实现定义的类型 在c编译器里有3中类型定义,在“implementation defined”中选择,如下: size_t 一种无符号必需类型通过sizeof操作表示返回类型 ptrdiff_t 一种有有符号必需类型用减法运算的两个指针来表示 wchar_t 它反映了类型的范围内的整数类型字符文本和宽字符字符串 在Data Types下的Intrinsic Types条目控制这些类型的方法实施,需要以匹配编译器配置环境。所载入的任何相应类型声明头文件(e.g. stddef.h, stdio.h)必须反映内在匹配值类型。如果不符合,qac提示等级9的警告,如有必要,检查您的头文件确定适当的设置这些选项。 如上所述:QAC随提供一套标准库的头文件,如果想改变这些类型定义,必须先明白QAC内部的定义类型,因为那些头文件包含一些声明ptrdiff_t, size_t 和wchar_t,还有3种宏指令定义PRQA_PTRDIFF_T, PRQA_SIZE_T,和PRQA_WCHAR_T, 3.1.4、编译器扩展 许多编译器制造商实施 ISO C 的扩展语言定义来利用特定的硬件环境。特别是在嵌入式软件代码的速度和空间是重要 使用的语言扩展的危险是他们妥协可移植性。源代码越来越依赖于编译器和硬件环境。 QA C 是能够分析各种不同的语言变体和扩展,但它不是通常能够解释扩展在语义上。通常,必须配置该工具等,非标准关键字将被忽略。 有几种方法可以为此配置QAC,看附录B–extensions部分

64,642

社区成员

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

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