业务基类对象BaseBLL
using System;
using System.Collections;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.Common;
using System.Reflection; using WHC.Pager.Entity;
using WHC.Framework.Commons; namespace WHC.Framework.ControlUtil
{
/// <summary>
/// 业务基类对象
/// </summary>
/// <typeparam name="T">业务对象类型</typeparam>
public class BaseBLL<T> where T : BaseEntity, new()
{
#region 构造函数 private string dalName = ""; /// <summary>
/// BLL业务类的全名(子类必须实现),可使用this.GetType().FullName
/// </summary>
protected string bllFullName; /// <summary>
/// 数据访问层程序集的清单文件的文件名,不包括其扩展名,可使用Assembly.GetExecutingAssembly().GetName().Name
/// </summary>
protected string dalAssemblyName; /// <summary>
/// BLL命名空间的前缀(BLL.)
/// </summary>
protected string bllPrefix = "BLL."; /// <summary>
/// 基础数据访问层接口对象
/// </summary>
protected IBaseDAL<T> baseDal = null; /// <summary>
/// 默认构造函数,调用后需手动调用一次 Init() 方法进行对象初始化
/// </summary>
public BaseBLL() { } /// <summary>
/// 参数赋值后,初始化相关对象
/// </summary>
/// <param name="bllFullName">BLL业务类的全名(子类必须实现),子类构造函数传入this.GetType().FullName</param>
/// <param name="dalAssemblyName">数据访问层程序集的清单文件的文件名,不包括其扩展名。设置为NULL或默认为Assembly.GetExecutingAssembly().GetName().Name</param>
/// <param name="bllPrefix">BLL命名空间的前缀(BLL.)</param>
/// <param name="dbConfigName">数据库配置项名称</param>
protected void Init(string bllFullName, string dalAssemblyName = null, string dbConfigName = null, string bllPrefix = "BLL.")
{
if (string.IsNullOrEmpty(bllFullName))
throw new ArgumentNullException("子类未设置bllFullName业务类全名!"); if (string.IsNullOrEmpty(dalAssemblyName))
{
dalAssemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
} //赋值,准备构建对象
this.bllFullName = bllFullName;
this.dalAssemblyName = dalAssemblyName;
this.bllPrefix = bllPrefix; #region 根据不同的数据库类型,构造相应的DAL层
AppConfig config = new AppConfig();
string dbType = config.AppConfigGet("ComponentDbType");
if (string.IsNullOrEmpty(dbType))
{
dbType = "sqlserver";
}
dbType = dbType.ToLower(); string DALPrefix = "";
if (dbType == "sqlserver")
{
DALPrefix = "DALSQL.";
}
else if (dbType == "access")
{
DALPrefix = "DALAccess.";
}
else if (dbType == "oracle")
{
DALPrefix = "DALOracle.";
}
else if (dbType == "sqlite")
{
DALPrefix = "DALSQLite.";
}
else if (dbType == "mysql")
{
DALPrefix = "DALMySql.";
}
#endregion this.dalName = bllFullName.Replace(bllPrefix, DALPrefix);//替换中级的BLL.为DAL.,就是DAL类的全名
baseDal = Reflect<IBaseDAL<T>>.Create(this.dalName, dalAssemblyName);//构造对应的DAL数据访问层的对象类 if (!string.IsNullOrEmpty(dbConfigName))
{
baseDal.SetDbConfigName(dbConfigName); //设置数据库配置项名称
}
} /// <summary>
/// 调用前检查baseDal是否为空引用
/// </summary>
protected void CheckDAL()
{
if (baseDal == null)
{
throw new ArgumentNullException("baseDal", "未能成功创建对应的DAL对象,请在BLL业务类构造函数中调用base.Init(**,**)方法,如base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);");
}
} #endregion #region 对象添加、修改、查询接口 /// <summary>
/// 插入指定对象到数据库中
/// </summary>
/// <param name="obj">指定的对象</param>
/// <param name="trans">事务对象</param>
/// <returns>执行操作是否成功。</returns>
public virtual bool Insert(T obj, DbTransaction trans = null)
{
CheckDAL();
return baseDal.Insert(obj, trans);
} /// <summary>
/// 插入指定对象到数据库中
/// </summary>
/// <param name="obj">指定的对象</param>
/// <param name="trans">事务对象</param>
/// <returns>执行成功返回新增记录的自增长ID。</returns>
public virtual int Insert2(T obj, DbTransaction trans = null)
{
CheckDAL();
return baseDal.Insert2(obj, trans);
} /// <summary>
/// 更新对象属性到数据库中
/// </summary>
/// <param name="obj">指定的对象</param>
/// <param name="primaryKeyValue">主键的值</param>
/// <param name="trans">事务对象</param>
/// <returns>执行成功返回<c>true</c>,否则为<c>false</c>。</returns>
public virtual bool Update(T obj, object primaryKeyValue, DbTransaction trans = null)
{
CheckDAL();
return baseDal.Update(obj, primaryKeyValue, trans);
} /// <summary>
/// 更新数据到数据表中
/// </summary>
/// <param name="commandType">SQL类型</param>
/// <param name="sql">sql或者存储过程</param>
/// <param name="trans">事务对象</param>
/// <returns>执行成功返回<c>true</c>,否则为<c>false</c>。</returns>
public virtual bool Update(CommandType commandType, string sql, DbTransaction trans = null)
{
CheckDAL();
return baseDal.Update(commandType, sql, trans);
} /// <summary>
/// 更新某个表一条记录(只适用于用单键,用string类型作键值的表)
/// </summary>
/// <param name="id">ID号</param>
/// <param name="recordField">Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
/// <param name="targetTable">需要操作的目标表名称</param>
/// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
public virtual bool Update(object id, Hashtable recordField, string targetTable, DbTransaction trans)
{
CheckDAL();
return baseDal.Update(id, recordField, targetTable, trans);
} /// <summary>
/// 插入或更新对象属性到数据库中
/// </summary>
/// <param name="obj">指定的对象</param>
/// <param name="primaryKeyValue">主键的值</param>
/// <param name="trans">事务对象</param>
/// <returns>执行成功返回<c>true</c>,否则为<c>false</c>。</returns>
public virtual bool InsertUpdate(T obj, object primaryKeyValue, DbTransaction trans = null)
{
CheckDAL();
return baseDal.InsertUpdate(obj, primaryKeyValue, trans);
} /// <summary>
/// 如果不存在记录,则插入对象属性到数据库中
/// </summary>
/// <param name="obj">指定的对象</param>
/// <param name="primaryKeyValue">主键的值</param>
/// <param name="trans">事务对象</param>
/// <returns>执行插入成功返回<c>true</c>,否则为<c>false</c>。</returns>
public virtual bool InsertIfNew(T obj, object primaryKeyValue, DbTransaction trans = null)
{
CheckDAL();
return baseDal.InsertIfNew(obj, primaryKeyValue, trans);
} /// <summary>
/// 执行SQL查询语句,返回查询结果的所有记录的第一个字段,用逗号分隔。
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="trans">事务对象</param>
/// <returns>
/// 返回查询结果的所有记录的第一个字段,用逗号分隔。
/// </returns>
public virtual string SqlValueList(string sql, DbTransaction trans = null)
{
CheckDAL();
return baseDal.SqlValueList(sql, trans);
} /// <summary>
/// 执行SQL查询语句,返回所有记录的DataTable集合。
/// </summary>
/// <param name="sql">SQL查询语句</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable SqlTable(string sql, DbTransaction trans = null)
{
CheckDAL();
return baseDal.SqlTable(sql, trans);
} /// <summary>
/// 执行SQL查询语句,返回所有记录的DataTable集合。
/// </summary>
/// <param name="sql">SQL查询语句</param>
/// <param name="parameters">参数集合</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable SqlTable(string sql, DbParameter[] parameters, DbTransaction trans = null)
{
CheckDAL();
return baseDal.SqlTable(sql, parameters, trans);
} /// <summary>
/// 查询数据库,检查是否存在指定ID的对象
/// </summary>
/// <param name="key">对象的ID值</param>
/// <param name="trans">事务对象</param>
/// <returns>存在则返回指定的对象,否则返回Null</returns>
public virtual T FindByID(object key, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindByID(key, trans);
} /// <summary>
/// 根据条件查询数据库,如果存在返回第一个对象
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="trans">事务对象</param>
/// <returns>指定的对象</returns>
public virtual T FindSingle(string condition, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindSingle(condition, trans);
} /// <summary>
/// 根据条件查询数据库,如果存在返回第一个对象
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="orderBy">排序条件</param>
/// <param name="trans">事务对象</param>
/// <returns>指定的对象</returns>
public virtual T FindSingle(string condition, string orderBy, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindSingle(condition, orderBy, trans);
} /// <summary>
/// 查找记录表中最旧的一条记录
/// </summary>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual T FindFirst(DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindFirst(trans);
} /// <summary>
/// 查找记录表中最新的一条记录
/// </summary>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual T FindLast(DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindLast(trans);
} #endregion #region 返回集合的接口 /// <summary>
/// 根据ID字符串(逗号分隔)获取对象列表
/// </summary>
/// <param name="idString">ID字符串(逗号分隔)</param>
/// <param name="trans">事务对象</param>
/// <returns>符合条件的对象列表</returns>
public virtual List<T> FindByIDs(string idString, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindByIDs(idString, trans);
} /// <summary>
/// 根据条件查询数据库,并返回对象集合
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> Find(string condition, DbTransaction trans = null)
{
CheckDAL();
return baseDal.Find(condition, trans);
} /// <summary>
/// 根据条件查询数据库,并返回对象集合
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="orderBy">排序条件</param>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> Find(string condition, string orderBy, DbTransaction trans = null)
{
CheckDAL();
return baseDal.Find(condition, orderBy, trans);
} /// <summary>
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="info">分页实体</param>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> FindWithPager(string condition, PagerInfo info, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindWithPager(condition, info,trans);
} /// <summary>
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="info">分页实体</param>
/// <param name="fieldToSort">排序字段</param>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> FindWithPager(string condition, PagerInfo info, string fieldToSort, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindWithPager(condition, info, fieldToSort, trans);
} /// <summary>
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="info">分页实体</param>
/// <param name="fieldToSort">排序字段</param>
/// <param name="desc">是否降序</param>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> FindWithPager(string condition, PagerInfo info, string fieldToSort, bool desc, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindWithPager(condition, info, fieldToSort, desc, trans);
} /// <summary>
/// 返回数据库所有的对象集合
/// </summary>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> GetAll(DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetAll(trans);
} /// <summary>
/// 返回数据库所有的对象集合
/// </summary>
/// <param name="orderBy">自定义排序语句,如Order By Name Desc;如不指定,则使用默认排序</param>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> GetAll(string orderBy, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetAll(orderBy, trans);
} /// <summary>
/// 返回数据库所有的对象集合(用于分页数据显示)
/// </summary>
/// <param name="info">分页实体信息</param>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> GetAll(PagerInfo info, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetAll(info, trans);
} /// <summary>
/// 返回数据库所有的对象集合(用于分页数据显示)
/// </summary>
/// <param name="info">分页实体信息</param>
/// <param name="fieldToSort">排序字段</param>
/// <param name="desc">是否降序</param>
/// <param name="trans">事务对象</param>
/// <returns>指定对象的集合</returns>
public virtual List<T> GetAll(PagerInfo info, string fieldToSort, bool desc, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetAll(info, fieldToSort, desc, trans);
} /// <summary>
/// 返回所有记录到DataTable集合中
/// </summary>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable GetAllToDataTable(DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetAllToDataTable(trans);
} /// <summary>
/// 返回所有记录到DataTable集合中
/// </summary>
/// <param name="orderBy">自定义排序语句,如Order By Name Desc;如不指定,则使用默认排序</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable GetAllToDataTable(string orderBy, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetAllToDataTable(orderBy, trans);
} /// <summary>
/// 根据分页条件,返回DataSet对象
/// </summary>
/// <param name="info">分页条件</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable GetAllToDataTable(PagerInfo info, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetAllToDataTable(info, trans);
} /// <summary>
/// 根据分页条件,返回DataSet对象
/// </summary>
/// <param name="info">分页条件</param>
/// <param name="fieldToSort">排序字段</param>
/// <param name="trans">事务对象</param>
/// <param name="desc">是否降序</param>
/// <returns></returns>
public virtual DataTable GetAllToDataTable(PagerInfo info, string fieldToSort, bool desc, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetAllToDataTable(info, fieldToSort, desc, trans);
} /// <summary>
/// 根据查询条件,返回记录到DataTable集合中
/// </summary>
/// <param name="condition">查询条件</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable FindToDataTable(string condition, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindToDataTable(condition, trans);
} /// <summary>
/// 根据查询条件,返回记录到DataTable集合中
/// </summary>
/// <param name="condition">查询条件</param>
/// <param name="pagerInfo">分页条件</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable FindToDataTable(string condition, PagerInfo pagerInfo, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindToDataTable(condition, pagerInfo, trans);
} /// <summary>
/// 根据条件查询数据库,并返回DataTable集合(用于分页数据显示)
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="info">分页实体</param>
/// <param name="fieldToSort">排序字段</param>
/// <param name="desc">是否降序</param>
/// <param name="trans">事务对象</param>
/// <returns>指定DataTable的集合</returns>
public virtual DataTable FindToDataTable(string condition, PagerInfo info, string fieldToSort, bool desc, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindToDataTable(condition, info, fieldToSort, desc, trans);
} /// <summary>
/// 获取字段列表
/// </summary>
/// <param name="fieldName">字段名称</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual List<string> GetFieldList(string fieldName, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetFieldList(fieldName, trans);
} /// <summary>
/// 根据条件,获取某字段数据字典列表
/// </summary>
/// <param name="fieldName">字段名称</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public List<string> GetFieldListByCondition(string fieldName, string condition, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetFieldListByCondition(fieldName, condition, trans);
} /// <summary>
/// 根据条件,从视图里面获取记录
/// </summary>
/// <param name="viewName">视图名称</param>
/// <param name="condition">查询条件</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable FindByView(string viewName, string condition, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindByView(viewName, condition, trans);
} /// <summary>
/// 根据条件,从视图里面获取记录
/// </summary>
/// <param name="viewName">视图名称</param>
/// <param name="condition">查询条件</param>
/// <param name="sortField">排序字段</param>
/// <param name="isDescending">是否为降序</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable FindByView(string viewName, string condition, string sortField, bool isDescending, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindByView(viewName, condition, sortField, isDescending, trans);
} /// <summary>
/// 根据条件,从视图里面获取记录
/// </summary>
/// <param name="viewName">视图名称</param>
/// <param name="condition">查询条件</param>
/// <param name="sortField">排序字段</param>
/// <param name="isDescending">是否为降序</param>
/// <param name="info">分页条件</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual DataTable FindByViewWithPager(string viewName, string condition, string sortField, bool isDescending, PagerInfo info, DbTransaction trans = null)
{
CheckDAL();
return baseDal.FindByViewWithPager(viewName, condition, sortField, isDescending, info, trans);
} #endregion #region 基础接口 /// <summary>
/// 获取表的所有记录数量
/// </summary>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual int GetRecordCount(DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetRecordCount(trans);
} /// <summary>
/// 获取表的指定条件记录数量
/// </summary>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual int GetRecordCount(string condition, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetRecordCount(condition, trans);
} /// <summary>
/// 根据condition条件,判断是否存在记录
/// </summary>
/// <param name="condition">查询的条件</param>
/// <param name="trans">事务对象</param>
/// <returns>如果存在返回True,否则False</returns>
public virtual bool IsExistRecord(string condition, DbTransaction trans = null)
{
CheckDAL();
return baseDal.IsExistRecord(condition, trans);
} /// <summary>
/// 查询数据库,检查是否存在指定键值的对象
/// </summary>
/// <param name="fieldName">指定的属性名</param>
/// <param name="key">指定的值</param>
/// <param name="trans">事务对象</param>
/// <returns>存在则返回<c>true</c>,否则为<c>false</c>。</returns>
public virtual bool IsExistKey(string fieldName, object key, DbTransaction trans = null)
{
CheckDAL();
return baseDal.IsExistKey(fieldName, key, trans);
} /// <summary>
/// 根据主键和字段名称,获取对应字段的内容
/// </summary>
/// <param name="key">指定对象的ID</param>
/// <param name="fieldName">字段名称</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public virtual string GetFieldValue(object key, string fieldName, DbTransaction trans = null)
{
CheckDAL();
return baseDal.GetFieldValue(key, fieldName, trans);
} /// <summary>
/// 根据指定对象的ID,从数据库中删除指定对象
/// </summary>
/// <param name="key">指定对象的ID</param>
/// <param name="trans">事务对象</param>
/// <returns>执行成功返回<c>true</c>,否则为<c>false</c>。</returns>
public virtual bool Delete(object key, DbTransaction trans = null)
{
CheckDAL();
return baseDal.Delete(key, trans);
} /// <summary>
/// 根据指定条件,从数据库中删除指定对象
/// </summary>
/// <param name="condition">删除记录的条件语句</param>
/// <param name="trans">事务对象</param>
/// <returns>执行成功返回<c>true</c>,否则为<c>false</c>。</returns>
public virtual bool DeleteByCondition(string condition, DbTransaction trans = null)
{
CheckDAL();
return baseDal.DeleteByCondition(condition, trans);
} /// <summary>
/// 打开数据库连接,并创建事务对象
/// </summary>
public virtual DbTransaction CreateTransaction()
{
CheckDAL();
return baseDal.CreateTransaction();
} /// <summary>
/// 打开数据库连接,并创建事务对象
/// </summary>
/// <param name="level">事务级别</param>
public virtual DbTransaction CreateTransaction(IsolationLevel level)
{
CheckDAL();
return baseDal.CreateTransaction(level);
} #endregion #region 其他接口
/// <summary>
/// 初始化数据库表名
/// </summary>
/// <param name="tableName">数据库表名</param>
public virtual void InitTableName(string tableName)
{
CheckDAL();
baseDal.InitTableName(tableName);
} /// <summary>
/// 获取表的字段名称和数据类型列表
/// </summary>
/// <returns></returns>
public virtual DataTable GetFieldTypeList()
{
CheckDAL();
return baseDal.GetFieldTypeList();
} /// <summary>
/// 获取字段中文别名(用于界面显示)的字典集合
/// </summary>
/// <returns></returns>
public virtual Dictionary<string, string> GetColumnNameAlias()
{
CheckDAL();
return baseDal.GetColumnNameAlias();
} /// <summary>
/// 获取指定字段的报表数据
/// </summary>
/// <param name="fieldName">表字段</param>
/// <param name="condition">查询条件</param>
/// <returns></returns>
public virtual DataTable GetReportData(string fieldName, string condition)
{
CheckDAL();
return baseDal.GetReportData(fieldName, condition);
}
#endregion
}
}
业务基类对象BaseBLL的更多相关文章
- C++中基类对象的引用
代码: #include <iostream> #include <cstdio> using namespace std; class A{ public: void pri ...
- C++派生类中如何初始化基类对象(五段代码)
今天收到盛大的面试,问我一个问题,关于派生类中如何初始化基类对象,我在想派生类对于构造函数不都是先构造基类对象,然后在构造子类对象,但是如果我们在成员初始化列表先初始化派生类的私有成员,在函数内去调用 ...
- 从汇编看c++中含有虚基类对象的析构
c++中,当继承结构中含有虚基类时,在构造对象时编译器会通过将一个标志位置1(表示调用虚基类构造函数),或者置0(表示不调用虚基类构造函数)来防止重复构造虚基类子对象.如下图菱形结构所示: 当构造类B ...
- 关于派生类访问基类对象的保护变量的问题 --Coursera
https://class.coursera.org/pkupop-001/forum/thread?thread_id=350 郭天魁· 6 months ago 在课件中我们知道如下程序是不能 ...
- [c++]基类对象作为函数參数(赋值兼容规则)
编程处理教师的基本情况. 要求: 1.定义一个"person"类.用来存储及处理人的姓名.性别.年龄,成员函数自定: 2.定义"teacher"类,公有继承&q ...
- C++派生类与基类对象赋值情况
一 .普通赋值 (同名隐藏) 子类对象调用和父类相同的函数名,该父类的函数名会被隐藏,只会调用子类的函数. Class A { public: void show(); void show(int); ...
- C++:基类与派生类对象之间的赋值兼容关系
4.5 基类与派生类对象之间的赋值兼容关系 在一定条件下,不同类型的数据之间可以进行类型转换,例如可以将整型数据赋给双精度型变量. 在赋值之前,先把整型数据转换为双精度型数据,然后再把它双精度型变量. ...
- c++,派生类对象可以对基类赋值,基类对派生类不可以赋值
派生类对象可以对基类对象赋值,赋值时属于派生类独有的部分就舍弃不用. #include <iostream> using namespace std; class DemoA { publ ...
- 派生类地址比基类地址少4(CDerived对象的起始地址存放的是虚表指针vptr,也就是子类的第一项内容。接下来的是基类的成员变量,接下来再是自身的成员变量)
大家对虚表并不陌生,都知道每个含有虚函数的类对象都有1个虚指针,但是在现实使用中,却总是因为这而调试半天,才发现原来是虚指针惹的祸.我这几天在调试代码时候也中招了,我的问题是这样的,如下图,CTree ...
随机推荐
- 结构体和typedef
在C语言中,可以使用结构体(Struct)来存放一组不同类型的数据.结构体的定义形式为: struct 结构体名{ 结构体所包含的变量或数组}; 结构体是一种集合,它里面包含了多个变量或数组,它 ...
- 拾遗:vim 配置(个人适用,仅供参考)
~/.vimrc "===================通用配置====================== set encoding=utf- set statusline=%F%=[L ...
- js设置cookies
//写入cookies的方法 function setCookie(name, value, seconds) { seconds = seconds || 0; //seconds有值就直接赋值,没 ...
- 零基础如何快速学习好Python网络爬虫?
Python网络爬虫上手很快,能够尽早入门,可是想精通确实是需求些时间,需求达到爬虫工程师的级别更是需求煞费苦心了,接下来共享的学习道路是针对小白或许学习Python网络爬虫不久的同伴们. 学习网络爬 ...
- js try{}catch(e){}的理解
程序开发中,编程人员经常要面对的是如何编写代码来响应错误事件的发生,即例外处理(exception handlers).如果例外处理代码设计得周全,那么最终呈现给用户的就将是一个友好的界面.否则,就会 ...
- [已解决]报错: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Users/mac/Ana
报错代码: pip3 install gerapy 报错内容: Could not install packages due to an EnvironmentError: [Errno 13] Pe ...
- 计算两个日期之间相差的天数(带带负数) 支持格式YYYY-mm-dd和YYYY-mm-dd HH:mm:ss
/** * 计算两个日期之间相差的天数(带带负数) 支持格式YYYY-mm-dd比较 * @param higDate 减数 * @param lowDate 被减数 * @returns 差值天数 ...
- 44.Linked List Cycle II(环的入口节点)
Level: Medium 题目描述: Given a linked list, return the node where the cycle begins. If there is no cy ...
- css字体的样式与分类用法总结
字体的样式 color 设置文本的颜色(前景色) ,它会应用到元素的所有边框,除非被 border-color 或另外某个边框颜色属性覆盖. <style> .box1 { color: ...
- hashRouter and BrowserRouter
<html><body> <div> <button class="btn" onclick="btnFun();"& ...