PC-LINT检查的编译问题
2014-09-05 11:34
190 查看
1.
class A
{
char name[10];
public:
const char* getA() const //一定要有const,因为name是一个数组名即常量指针
{
return name;
}
}
2.
class TServiceTypeConfigItem
{
public:
char ServiceType[MaxServiceTypesLength+1];
char serviceTypeIp[MaxIPAddressLength+1];
TServiceTypeConfigItem()
{
memset(ServiceType, 0, sizeof(ServiceType));
memset(serviceTypeIp,0,sizeof(serviceTypeIp));
}
public:
const char* getServiceType() const { return ServiceType;}
bool setServiceType(PCSTR ServiceType)
{
safeCopyStr(this->ServiceType,ServiceType,MaxServiceTypesLength);
return true;
}
const char* getServiceTypeIp() const { return serviceTypeIp;}
bool setServiceTypeIp(PCSTR serviceTypeIp)
{
safeCopyStr(this->serviceTypeIp,serviceTypeIp,MaxIPAddressLength);
return true;
}
};
class xxx
{
TServiceTypeConfigItem m_ServiceTypeConfigItem[MAX_IPTOSERVICETYPE_NUM];//是一个数组类型
public:
const TServiceTypeConfigItem* getServiceTypeConfigItem(int index) const//这里必须是const,因为是数组名加偏移
{
if ((index < 0) || (index > m_IpToServiceTypeNum))
{return NULL;}
return m_ServiceTypeConfigItem+ index;
}
}
const_cast<TServiceTypeConfigItem*>(getServiceTypeConfigItem(i))->getServiceType()//这里返回的是const型的,再调用getgetServiceType函数就错了,因为const型对像或者指针不能调用非const型函数,所以要去掉const属性。
class A
{
char name[10];
public:
const char* getA() const //一定要有const,因为name是一个数组名即常量指针
{
return name;
}
}
2.
class TServiceTypeConfigItem
{
public:
char ServiceType[MaxServiceTypesLength+1];
char serviceTypeIp[MaxIPAddressLength+1];
TServiceTypeConfigItem()
{
memset(ServiceType, 0, sizeof(ServiceType));
memset(serviceTypeIp,0,sizeof(serviceTypeIp));
}
public:
const char* getServiceType() const { return ServiceType;}
bool setServiceType(PCSTR ServiceType)
{
safeCopyStr(this->ServiceType,ServiceType,MaxServiceTypesLength);
return true;
}
const char* getServiceTypeIp() const { return serviceTypeIp;}
bool setServiceTypeIp(PCSTR serviceTypeIp)
{
safeCopyStr(this->serviceTypeIp,serviceTypeIp,MaxIPAddressLength);
return true;
}
};
class xxx
{
TServiceTypeConfigItem m_ServiceTypeConfigItem[MAX_IPTOSERVICETYPE_NUM];//是一个数组类型
public:
const TServiceTypeConfigItem* getServiceTypeConfigItem(int index) const//这里必须是const,因为是数组名加偏移
{
if ((index < 0) || (index > m_IpToServiceTypeNum))
{return NULL;}
return m_ServiceTypeConfigItem+ index;
}
}
const_cast<TServiceTypeConfigItem*>(getServiceTypeConfigItem(i))->getServiceType()//这里返回的是const型的,再调用getgetServiceType函数就错了,因为const型对像或者指针不能调用非const型函数,所以要去掉const属性。
相关文章推荐
- 静态代码检查工具PC-Lint(一)
- 静态代码检查工具PC-Lint(二)
- VS2008配置PC Lint9 (静态代码检查工具PC-Lint)
- pc-lint静态代码检查工具
- VS2008配置PC Lint (静态代码检查工具PC-Lint)
- 静态代码检查工具PC-Lint(一)
- 静态代码检查工具PC-LINT
- MiniGUI v1.3.3在PC上的配置和编译过程(常见问题解决方法)
- PC-Lint的代码检查功能
- Android-Lint 检查问题列表
- C++语言代码检查工具PC-Lint简介
- C++语言代码检查工具PC-Lint四步速成
- PC-Lint和SI集成小问题
- C++语言代码检查工具PC-Lint简介
- PC_LinT 代码检查工具(KEIL)
- 静态代码检查工具PC-Lint(二)
- 2007-09-19 PC上配置编译MiniGUI v1.3.3之我的问题
- C++语言代码检查工具PC-Lint四步速成
- VS2008配置PC Lint (静态代码检查工具PC-Lint)
- PC-Lint 检查linux源码