0816,特殊数据成员/成员函数,对象组织,delete/new,单例模式

2024-08-29 00:12

本文主要是介绍0816,特殊数据成员/成员函数,对象组织,delete/new,单例模式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

01 特殊的数据成员 (是我写作业不看题目

1,常量数据成员
加上const 的数据成员,加上之后只能在声明和初始化队列中进行初始化,初始化之后不能进行赋值操作

2,引用数据数据成员
用引用方式创建的数据成员
引用数据成员需要在初始化列表中进行初始化
需要绑定一个已经存在的,在引用成员的生命周期内始终有效的变量(对象

3,对象成员
一个类的对象是其他类的数据成员
coution:
初始化列表写对象,不写类名,不能在声明对象成员时直接用有参构造创建
如果在初始化列表中没有显示的初始化对象成员,编译器回自动调用对象成员的默认无参构造或者所有参数都有默认值的有参
堆空间资源回收顺序(类的对象-->对象成员)

4,静态数据成员
加上static修饰的数据成员
存储在全局/静态区,不占据对象的存储空间,静态数据成员被整个类的所有对象共享
规则:
4.1 private 的静态数据成员无法在类之外直接访问
4.2 初始化必须放在类外(一般紧接类定义
4.3 初始化时不能在前面+static,要加类名+作用域限定符
4.4 多条初始化顺序和声明顺序一致
4.5 对象访问 & 类名::访问

001const.cc

#include <iostream>
using std::cout;
using std::endl;class Point{
public:Point()//只能用 这种 严格意义的初始化/* :_ix(0),_iy(0) */{cout<<"Point()"<<endl;}Point(int x,int y=1):_ix(x),_iy(y) //const int _ix=x;//can't _ix=x;{cout<<"Point(int ,int)"<<endl;}Point(const Point & p):_ix(p._ix),_iy(p._iy){cout<<"Point(Point &)"<<endl;}void print(){ cout<<_ix<<"\t\t"<<_iy<<endl; }
private:const  int _ix=1;const  int _iy=1;//备胎中的备胎//只能算声明/* const  int _ix; *//* const  int _iy; */
};void test(){Point pt1;Point pt2(5);Point pt(1,2);Point pt3(pt1);/* pt3=pt2; *///声明了常量数据成员,不能进行常规意义的赋值操作pt1.print();
}int main(void)
{test();return 0;
}

002refmember.cc

#include <iostream>
using std::cout;
using std::endl;int gNum=100;
//只能绑定一个已经存在,在引用期间成员的生命周期内
//始终有效的变量(对象
class Point{
public:Point():_ix(0),_iy(0),_ref(_ix){cout<<"Point()"<<endl;}Point(int x,int y=1):_ix(x),_iy(y) //const int _ix=x;/* ,_ref(_ix) */{cout<<"Point(int ,int)"<<endl;}/* Point(int x,int y,int z) *//*     :_ix(x),_iy(y) //const int _ix=x; *//*     ,_ref(z) *//*     {cout<<"Point(int ,int,int)"<<endl;} */Point(const Point & p):_ix(p._ix),_iy(p._iy),_ref(p._ref){cout<<"Point(Point &)"<<endl;}void print(){ cout<<_ix<<"\t\t"<<_iy<<"\t\t"<<_ref<<endl; }
private:int _ix;int _iy;/* int & _ref; */int & _ref=gNum;/* int & _ref=_iy; */
};void test(){Point pt1;/* Point pt2(5,6,7); //7生命周期?一个牛逼的数字 */Point pt2(pt1);Point pt3(1,2);Point pt4(9);/* pt3=pt2; *///声明了常量数据成员,不能进行常规意义的赋值操作pt1.print();pt2.print();pt3.print();pt4.print();
}int main(void)
{test();return 0;
}

 003object.cc

#include <iostream>
using std::cout;
using std::endl;class Point{
public:Point():_ix(0),_iy(0){cout<<"Point()"<<endl;}Point(int x=1,int y=1):_ix(x),_iy(y) //const int _ix=x;{cout<<"Point(int ,int)"<<endl;}Point(const Point & p):_ix(p._ix),_iy(p._iy){cout<<"Point(Point &)"<<endl;}~Point(){cout<<"~Point()"<<endl;}void print(){ cout<<_ix<<" "<<_iy; }
private:int _ix;int _iy;
};class Line{
public:Line(int x1,int y1,int x2,int y2):_pt1(x1,y1),_pt2(x2,y2)/* :_pt1(),_pt2() *///搞不懂啊啊啊,为撒不初始化的不行喵,创建worning,打印error//LIne的构造函数的初始化列表中//需要显示调用point的构造完成对象成员的初始化//如果没有,编译器自动调用POINT的无参构造//活着所有参数都有默认值的有参构造{cout<<"Line(int*4)"<<endl;}~Line(){cout<<"~line"<<endl;}void printLine(){_pt1.print();cout<<"---->";_pt2.print();cout<<endl;}
private:Point _pt1;Point _pt2;
};void test(){Line l(1,2,3,4);l.printLine();/* Line l1(); *//* l1.printLine(); */
}int main(void)
{test();return 0;
}

04_static_member.cc 

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;class Computer{
public:/* void init(const char* brand,int price){ *//*     strcpy(_brand,brand); *//*     _price=price; *//* } */void printBrandPrice(){cout<<_brand<<"\t";cout<<_price<<endl;}static int get_totalprice(){return _totalprice;}
//----------------------------//
/* private: */Computer(const char* brand,int price): _brand(new char[strlen(brand)+1]()), _price(price){strcpy(_brand,brand);// 否则没有赋值喵,不输出_totalprice+=_price;cout<<_brand<<"\t\t"<<"Computer(char* int)"<<endl;}Computer(const Computer & c): _brand(new char[strlen(c._brand)+1]()), _price(c._price){strcpy(_brand,c._brand);// 否则没有赋值喵,不输出_totalprice+=_price;cout<<"Computer(cosnt Computer &)"<<endl;}Computer & operator=(const Computer & c){if(this!=&c){delete [] _brand;_brand=new char[strlen(c._brand)+1]();strcpy(_brand,c._brand);_price=c._price;_totalprice+=_price;}return *this;}
//----------------------------//~Computer(){cout<<_brand<<"\t\t";if(_brand){delete  _brand;  //coution_brand=nullptr;   //加上,信任行为喵_totalprice-=_price;}cout<<"~Computer"<<endl;}
private:char* _brand;int _price;static int  _totalprice; 
};
int Computer::_totalprice=0; //----------------------------//
void test(){cout<<sizeof(Computer)<<endl;cout<<Computer::get_totalprice()<<endl;Computer p1("xixi",66);cout<<p1.get_totalprice()<<endl;Computer p2("paxi",66);cout<<p1.get_totalprice()<<endl;
}
int main(void)
{test();return 0;
}

05_constMember.cc

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;class Computer{
public:void init(int price)/*const*/{_price=price;}void printBrandPrice()const{cout<<_brand<<"\t";cout<<_price<<"\tconst_print"<<endl;}
//----------------------------//
/* private: */Computer(const char* brand,int price): _brand(new char[strlen(brand)+1]()), _price(price){strcpy(_brand,brand);// 否则没有赋值喵,不输出cout<<_brand<<"\t\t"<<"Computer(char* int)"<<endl;}Computer(const Computer & c): _brand(new char[strlen(c._brand)+1]()), _price(c._price){strcpy(_brand,c._brand);// 否则没有赋值喵,不输出cout<<"Computer(cosnt Computer &)"<<endl;}Computer & operator=(const Computer & c){if(this!=&c){delete [] _brand;_brand=new char[strlen(c._brand)+1]();strcpy(_brand,c._brand);_price=c._price;}return *this;}
//----------------------------//~Computer(){cout<<_brand<<"\t\t";if(_brand){delete  _brand;  //coution_brand=nullptr;   //加上,信任行为喵}cout<<"~Computer"<<endl;}
private:char* _brand;int _price;
};//----------------------------//
void test(){cout<<sizeof(Computer)<<endl;Computer p1("xixi",66);p1.init(7888);//不能修改对象的数据成员p1.printBrandPrice();cout<<endl;const Computer p2("paxi",66);p2.printBrandPrice();/* p2.init(7888); */cout<<endl;
}
int main(void)
{test();return 0;
}

06_constfuction.cc

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;class Computer{
public:void init(int price)/*const*/{_price=price;}void printBrandPrice(const Computer & c)const{/* for(int i=0;i<strlen(c._brand)+1;i++){ *//*     _brand[i]=c._brand[i]; *//* } *///尽量避免cout<<_brand<<"\t";cout<<_price<<"\tconst_print"<<endl;}//----------------------------///* private: */Computer(const char* brand,int price): _brand(new char[strlen(brand)+1]()), _price(price){strcpy(_brand,brand);// 否则没有赋值喵,不输出cout<<_brand<<"\t\t"<<"Computer(char* int)"<<endl;}Computer(const Computer & c): _brand(new char[strlen(c._brand)+1]()), _price(c._price){strcpy(_brand,c._brand);// 否则没有赋值喵,不输出cout<<"Computer(cosnt Computer &)"<<endl;}Computer & operator=(const Computer & c){if(this!=&c){delete [] _brand;_brand=new char[strlen(c._brand)+1]();/* strcpy(_brand,c._brand); */_price=c._price;}return *this;}//----------------------------//~Computer(){cout<<_brand<<"\t\t";if(_brand){delete  _brand;  //coution_brand=nullptr;   //加上,信任行为喵}cout<<"~Computer"<<endl;}
private:/* const char* _brand;//+brand[]也不行,只读变量不可赋值 */char* _brand;int _price;
};//----------------------------//
void test(){Computer p1("xixi",66);Computer p2("kaixin",66);p1.printBrandPrice(p2);cout<<endl;
}
int main(void)
{test();return 0;
}

07_PointArray.cc

#include <iostream>
using std::cout;
using std::endl;class Point{
public:Point():_ix(0),_iy(0){cout<<"Point()"<<endl;}Point(int x/*=1*/,int y=1):_ix(x),_iy(y) //const int _ix=x;{cout<<"Point(int ,int)"<<endl;}Point(const Point & p):_ix(p._ix),_iy(p._iy){cout<<"Point(Point &)"<<endl;}~Point(){cout<<"~Point()"<<endl;}Point & operator=(const Point & p){_ix=p._ix;_iy=p._iy;return *this;}void print(){ cout<<_ix<<" "<<_iy<<endl; }
private:int _ix;int _iy;
};void test(){Point* p1=new Point(3,4);p1->print();(*p1).print();delete p1;//()确保进行了初始化,初始化为相应类信息的默认值int *p=new int();cout<<*p<<endl;delete p;//Point 类型的默认值是无参构造初始化的Point对象Point* p2=new Point();//调用模糊p2->print();delete p2;//------------------------------//cout<<endl;Point p4(7,5);Point p3(3,5);Point p6(6,5);Point arr[3]={p4,p3,p6};//Point(const Point &)cout<<&p4<<endl;cout<<arr<<endl;cout<<endl;Point ar1[2]={Point(1,2),Point(3,4)};ar1[0].print();(ar1+1)->print();cout<<endl;Point ar2[2]={{2,2},{5,5}};
}int main(void)
{test();return 0;
}

08_Student.cc

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;class Student
{
public:Student(int id, const char * name): _id(id), _name(new char[strlen(name) + 1]()){strcpy(_name, name);cout << "Student()" << endl;}~Student(){if(_name){delete [] _name;_name = nullptr;}}//------------------------------//void operator delete(void * pointer){cout<<"operator delete"<<endl;free(pointer);}void* operator new(size_t sz){cout<<"operator new "<<endl;void* ret=malloc(sz);return ret;}//------------------------------//void print() const{cout << "id:" << _id << "\t"<< "name:" << _name << endl;}
private:int _id;char * _name;
};//------------------------------//
void test(){Student * s=new Student(3,"xixi");s->print();delete s;
}int main(void)
{test();return 0;
}

09_HeapStudent.cc

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;class Student
{
public:Student(int id, const char * name): _id(id), _name(new char[strlen(name) + 1]()){strcpy(_name, name);cout << "Student()" << endl;}~Student(){if(_name){delete [] _name;_name = nullptr;}}//------------------------------//void operator delete(void * pointer){cout<<"operator delete"<<endl;free(pointer);}void* operator new(size_t sz){cout<<"operator new "<<endl;void* ret=malloc(sz);return ret;}void destroy(){delete this;}//------------------------------//void print() const{cout << "id:" << _id << "\t"<< "name:" << _name << endl;}
private:int _id;char * _name;
};//------------------------------//
void test(){Student * s=new Student(3,"xixi");s->print();s->destroy();/* delete s; */
}int main(void)
{test();return 0;
}

10_StackStudent.cc

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;class Student
{
public:Student(int id, const char * name): _id(id), _name(new char[strlen(name) + 1]()){strcpy(_name, name);cout << "Student()" << endl;}~Student(){if(_name){delete [] _name;_name = nullptr;}}void print() const{cout << "id:" << _id << "\t"<< "name:" << _name << endl;}
private://------------------------------//void operator delete(void * pointer){cout<<"operator delete"<<endl;free(pointer);}void* operator new(size_t sz){cout<<"operator new "<<endl;void* ret=malloc(sz);return ret;}void destroy(){delete this;}//------------------------------//
private:int _id;char * _name;
};//------------------------------//
void test(){/* Student * s=new Student(3,"xixi"); */Student s(3,"xix");s.print();/* s.destroy(); *//* delete s; */
}int main(void)
{test();return 0;
}

static_single.cc

#include <iostream>
using std::cout;
using std::endl;class Point{
public:Point():_ix(0),_iy(0){cout<<"Point()"<<endl;}/* Point(const Point & p) *//*     :_ix(p._ix),_iy(p._iy) *//*     {cout<<"Point(Point &)"<<endl;} *///删除  拷贝构造效果更好?????//删除  赋值构造效果更好?????void print(){ cout<<_ix<<"\t\t"<<_iy<<endl; }static Point & getInstance(){static Point pt(2,8);//单例模式,只能初始化一次return pt;}//不是静态成员函数???
private:Point(int x,int y=1):_ix(x),_iy(y){cout<<"Point(int ,int)"<<endl;}//构造  私有~Point(){cout<<"~Point()"<<endl;}//析构  私有(四大金刚全部干掉喵
private:int _ix;int _iy;
};void test(){Point & pt1=Point::getInstance();Point & pt2=Point::getInstance();cout<<&pt1<<endl;cout<<&pt2<<endl;
}int main(void)
{test();return 0;
}

heap_single.cc 

#include <iostream>
using std::cout;
using std::endl;//堆上创建单例对象
class Point{
public:static Point * getInstance(){if(_pInstance==nullptr){_pInstance=new Point(1,2);} return _pInstance;}static void destroy(){if(_pInstance){delete _pInstance;_pInstance=nullptr;}cout<<"<<<delete heap"<<endl;}//C++11之后可以将成员函数从类中删除Point(Point & rhs)=delete;Point & operator=(const Point & rhs)=delete;void init(int x,int y){_ix=x;_iy=y;}//初始化和赋值分开void print(){ cout<<_ix<<"\t\t"<<_iy<<endl; }
private:Point():_ix(0),_iy(0){cout<<"Point()"<<endl;}Point(int x,int y):_ix(x),_iy(y) //const int _ix=x;{cout<<"Point(int ,int)"<<endl;}~Point(){cout<<"~point()"<<endl;}
private:int _ix;int _iy;static Point* _pInstance;//定义一个指针保存第一次创建的对象
};
Point * Point::_pInstance=nullptr;
//初始化void test(){//使用规范,避免多个指针拥有单例对象的管理权Point::getInstance()->print();Point::getInstance()->init(21,13);Point::getInstance()->print();Point::getInstance()->init(23,231);Point::getInstance()->print();Point::destroy();Point::destroy();Point::destroy();//多次执行也不会有double free的问题Point::getInstance()->print();Point::destroy();
}int main(void)
{test();return 0;
}

06 作业

01,特殊的成员函数有哪几种?各自的特点是什么? (坏,答了一个特殊的数据成员

1,static成员函数

0.1 静态成员函数不依赖于某一对象
0.2 静态成员函数可以通过对象调用,但更加常见的方式是通过类名加上作用域限定符调用
0.3 静态成员函数没有this指针
0.4 静态成员函数中无法直接使用成员名访问非静态的成员,只能访问静态数据成员或调用静态成员(因为没有this指针),但是非静态的成员函数可以访问静态成员
0.5 构造/析构/赋值运算符/拷贝构造比较特殊,可以在静态成员函数中调用(这四个函数不能设置为静态成员函数,他们会访问所有的成员对象,但是静态成员函数没有this指针)

2,const成员函数

0.1 cosnt 成员函数中,不能修改对象的数据成员
0.2 当编译器发现该函数是const成员函数时,会自动将this指针设置为双重const限定的指针

const 对象与const 成员函数的规则:

当类中有const成员函数和非const成员函数重载时,const对象会调用const成员函数,非const对象会调用非const成员函数
当类中只有一个const成员函数时,无论const对象还是非const对象都可以调用这个版本
当类中只有一个非const成员函数时,const对象就不能调用非const版本

总结:如果一个成员函数中确定不会修改数据成员,就把它定义为const成员函数

02,写出以下程序运行的结果。( )

class Sample 
{
public:Sample();void Display();
private:int i;static int k;
};Sample::Sample() 
{i=0;k++;
}void Sample::Display() 
{cout << "i=" << i << ",k=" << k << endl;
}int Sample::k=0;int main( ) 
{Sample a, b;a.Display();b.Display();return 0;
}

i=0,k=1(2)坏

i=0,k=2 

03,写出下面程序的结果:  11

#include <iostream>
using std::cout;
using std::endl;int i = 1;class Test
{
public:Test():_first(i++) //1  2,_second(i++)//2  3,_third(i++)//3  4,_fourth(_third)//3{_third = i;//4   _foruth=4}void print(){  cout << "result : " << _first + _second + _third + _fourth << endl;//1 2 4 4 =11}
private:int _first;int _second;int _third;int &_fourth;
};int main()
{Test test;test.print();return 0;
}

04,写出以下程序运行的结果。

#include <iostream>
#include <math.h>
using std::cout;
using std::endl;class Point	
{
public:Point(int xx = 0, int yy = 0) {X = xx;Y = yy;cout << "point构造函数被调用" << endl;}Point(Point &p);int GetX() {return X;}int GetY() {return Y;}private:int X,Y;
};Point::Point(Point &p)	
{X = p.X;Y = p.Y;cout << "X = " << X << " Y=" << Y << "Point拷贝构造函数被调用" << endl;
}class Distance	
{
public:	Distance(Point xp1, Point xp2);double GetDis(){return dist;}
private:	Point p1,p2;double dist;	
};//拷贝一次
Distance::Distance(Point xp1, Point xp2)
: p1(xp1)//拷贝一次
, p2(xp2)
{cout << "Distance构造函数被调用" << endl;double x = double(p1.GetX() - p2.GetX());double y = double(p1.GetY() - p2.GetY());dist = sqrt(x * x + y * y);
}int main()
{//point构造函数被调用//point构造函数被调用Point myp1(1,1), myp2(4,5);//X=1,Y=1,Point拷贝构造函数被调用//X=4,Y=5,Point拷贝构造函数被调用//X=1,Y=1,Point拷贝构造函数被调用//X=4,Y=5,Point拷贝构造函数被调用Distance myd(myp1, myp2);//Distance构造函数被调用cout << "The distance is:" ;//The distance is:distcout << myd.GetDis() << endl;return 0;
}

point构造函数被调用
point构造函数被调用
X = 4 Y=5Point拷贝构造函数被调用
X = 1 Y=1Point拷贝构造函数被调用
X = 1 Y=1Point拷贝构造函数被调用
X = 4 Y=5Point拷贝构造函数被调用
Distance构造函数被调用
The distance is:5  

05,写出以下程序运行的结果。   122444

#include <iostream>
using std::cout;
using std::endl;class MyClass
{
public:MyClass(int i = 0){cout << i;}MyClass(const MyClass &x){cout << 2;}MyClass &operator=(const MyClass &x){cout << 3;return *this;}~MyClass(){cout << 4;}
};
int main()
{MyClass obj1(1), obj2(2);//12MyClass obj3 = obj1;//==Myclass obj3(obj1);//32444return 0;
}

06,不考虑任何编译器优化(如:NRVO),下述代码的第10#会发生-fno-elide-constructors 编译时消除优化的影响

#include <iostream>
using std::cout;
using std::endl;class B
{
public:B(){cout << "B()" << endl;}~B(){cout << "~B()" << endl;}B(const B &rhs){cout << "B(const B&)" << endl;}B &operator=(const B &rhs){cout << "B &operator=(const B &s)" << endl;return  *this;}
};B func(const B &rhs)//cp  不是喵是赋值
{cout << "B func(const B &)" << endl;return rhs;
}int main(int argc, char **argv)
{B b1,b2;b2=func(b1);//10#//B func(const B &)//B(const B&)//B &operator=(const B &s)return 0;
}

B func(const B &)
B(const B&)
B &operator=(const B &s) 

07,new表达式和delete表达式的底层实现是什么?

1,对于自定义类型而言

使用new表达式的三个步骤:
1,调用operator new标准库函数申请未类型化的空间
2,在该空间上调用该类型的构造函数初始化对象
3,返回指向该对象的相应类型的指针

使用delete表达式···
1,调用析构函数,回收数据成员申请的资源(堆空间)
2,调用operator delete库函数回收本对象所在的空间

对于内置类型而言,则没有以上构造函数和析构函数执行的步骤

08,实现单例的Point类(将单例对象创建在堆上)

heap_single.cc 

09,实现一个单例的Computer类,包含品牌和价格信息。

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;class Computer{
public:static Computer * get(){if(!_pp){_pp=new Computer("xixi",520); }return _pp; } /* void* operator new(size_t sz){ *//*     void * ret=malloc(sz); *//*     return ret; *//* } *//* void operator delete(void * p){ *//*     free(p); *//* } */static void destory(){if(_pp){delete _pp;_pp=nullptr;}cout<<"<<<< destory"<<endl;}Computer(Computer & c)=delete;Computer & operator=(const Computer & c)=delete;void init(const char* brand,int price){strcpy(_brand,brand);_price=price;}void printBrandPrice(){cout<<_brand<<"\t";cout<<_price<<endl;}
private:Computer(const char* brand,int price): _brand(new char[strlen(brand)+1]()), _price(price){strcpy(_brand,brand);// 否则没有赋值喵,不输出cout<<_brand<<"\t\t"<<"Computer"<<endl;}~Computer(){cout<<_brand<<"\t\t";if(_brand){delete  _brand;  //coution_brand=nullptr;   //加上,信任行为喵}cout<<"~Computer"<<endl;}
private:char* _brand;int _price;static Computer * _pp; 
};
Computer*Computer::_pp=nullptr;void test(){Computer::get()->printBrandPrice();Computer::get()->init("jiajia",7758258);Computer::get()->printBrandPrice();Computer::get()->init("yueyue",51930);Computer::get()->printBrandPrice();Computer::destory();Computer::destory();Computer::destory();
}
void test01(){
}
int main(void)
{test();test01();return 0;
}

这篇关于0816,特殊数据成员/成员函数,对象组织,delete/new,单例模式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1116286

相关文章

Python函数作用域与闭包举例深度解析

《Python函数作用域与闭包举例深度解析》Python函数的作用域规则和闭包是编程中的关键概念,它们决定了变量的访问和生命周期,:本文主要介绍Python函数作用域与闭包的相关资料,文中通过代码... 目录1. 基础作用域访问示例1:访问全局变量示例2:访问外层函数变量2. 闭包基础示例3:简单闭包示例4

Linux下利用select实现串口数据读取过程

《Linux下利用select实现串口数据读取过程》文章介绍Linux中使用select、poll或epoll实现串口数据读取,通过I/O多路复用机制在数据到达时触发读取,避免持续轮询,示例代码展示设... 目录示例代码(使用select实现)代码解释总结在 linux 系统里,我们可以借助 select、

JavaScript对象转数组的三种方法实现

《JavaScript对象转数组的三种方法实现》本文介绍了在JavaScript中将对象转换为数组的三种实用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友... 目录方法1:使用Object.keys()和Array.map()方法2:使用Object.entr

Python中isinstance()函数原理解释及详细用法示例

《Python中isinstance()函数原理解释及详细用法示例》isinstance()是Python内置的一个非常有用的函数,用于检查一个对象是否属于指定的类型或类型元组中的某一个类型,它是Py... 目录python中isinstance()函数原理解释及详细用法指南一、isinstance()函数

python中的高阶函数示例详解

《python中的高阶函数示例详解》在Python中,高阶函数是指接受函数作为参数或返回函数作为结果的函数,下面:本文主要介绍python中高阶函数的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录1.定义2.map函数3.filter函数4.reduce函数5.sorted函数6.自定义高阶函数

Python中的sort方法、sorted函数与lambda表达式及用法详解

《Python中的sort方法、sorted函数与lambda表达式及用法详解》文章对比了Python中list.sort()与sorted()函数的区别,指出sort()原地排序返回None,sor... 目录1. sort()方法1.1 sort()方法1.2 基本语法和参数A. reverse参数B.

使用MapStruct实现Java对象映射的示例代码

《使用MapStruct实现Java对象映射的示例代码》本文主要介绍了使用MapStruct实现Java对象映射的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、什么是 MapStruct?二、实战演练:三步集成 MapStruct第一步:添加 Mave

C#使用iText获取PDF的trailer数据的代码示例

《C#使用iText获取PDF的trailer数据的代码示例》开发程序debug的时候,看到了PDF有个trailer数据,挺有意思,于是考虑用代码把它读出来,那么就用到我们常用的iText框架了,所... 目录引言iText 核心概念C# 代码示例步骤 1: 确保已安装 iText步骤 2: C# 代码程

Pandas处理缺失数据的方式汇总

《Pandas处理缺失数据的方式汇总》许多教程中的数据与现实世界中的数据有很大不同,现实世界中的数据很少是干净且同质的,本文我们将讨论处理缺失数据的一些常规注意事项,了解Pandas如何表示缺失数据,... 目录缺失数据约定的权衡Pandas 中的缺失数据None 作为哨兵值NaN:缺失的数值数据Panda

C++中处理文本数据char与string的终极对比指南

《C++中处理文本数据char与string的终极对比指南》在C++编程中char和string是两种用于处理字符数据的类型,但它们在使用方式和功能上有显著的不同,:本文主要介绍C++中处理文本数... 目录1. 基本定义与本质2. 内存管理3. 操作与功能4. 性能特点5. 使用场景6. 相互转换核心区别