c++_08_操作符重载(操作符重定义) 友元

1  操作符标记 

        单目操作符:        -    ++    --    *    ->    等

        双目操作符:        -    +    >    <    +=    -=    <<    >>    等

        三木操作符:        ? :  

2  操作符函数

2.0  前言

        C++编译器有能力把一个由操作数操作符组成的表达式,

        解释为对一个成员函数的调用,               a + b   -->   a.operator+( b )

        解释为对一个全员函数的调用。               a + b   -->   operator+( a,b )

        该  全员函数  或  成员函数  被称为操作符函数。两个函数不要重复定义。

        通过定义操作符函数,可以实现针对自定义类型的运算法则,并使之与基本类型一样参与各种表达式。

// complex_pre.cpp操作符函数
#include <iostream>
using namespace std;

class Human {
public:
    Human( int age=0, const char* name="无名" ) : m_age(age),m_name(name) {
        //【int m_age=age;】
        //【string m_name(name);】
    }
    void getinfo( ) {
        cout << "姓名: " << m_name << ", 年龄: " << m_age << endl;
    }
    Human sum( /* Human* this */ Human r ) {
        return Human(this->m_age+r.m_age, (this->m_name+"+"+r.m_name).c_str() );
    }
    Human sub( /* Human* this */ Human r ) {
        return Human(this->m_age-r.m_age, (this->m_name+"-"+r.m_name).c_str() );
    }
private:
    int m_age;
    string m_name;
};
// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Human a(22,"张飞"), b(20,"赵云"), c(25,"关羽"), d(32,"马超");

    Human res = a.sum(b); // a + b; ==> a.operator+(b)  或  operator+(a,b)
    res.getinfo( );

    res = c.sub(d); // c - d; ==> c.operator-(d)  或 operator-(c,d)
    res.getinfo( );
    return 0;
}

2.1  单目运算符表达式    #O / O#

        成员函数形式:    O.operator# ()

        全局函数形式:    operator# (O)

2.2  双目运算符表达式    L#R

        成员函数形式:    L.operator# (R)    左调右参:左操作数是用对象,操作数是数对象

        全局函数形式:    operator# (L,R)    左一右二:操作数是第参数,操作数是第参数

2.3  三目运算符表达式    F#S#T

        无法重载。

3  典型双目操作符

3.1  运算类:  +  -  *  /  等

        左操作数可以为非常左值常左值右值 

        右操作数可以为非常左值常左值右值 

        表达式的结果为右值 (即,不是引用就行)

// double_operator1.cpp
#include <iostream>
using namespace std;

class Human { // 授权类(授予朋友权利的类)
public:
    Human( int age=0, const char* name="无名" ) : m_age(age),m_name(name) {
        //【int m_age=age;】
        //【string m_name(name);】
    }
    void getinfo( ) {
        cout << "姓名: " << m_name << ", 年龄: " << m_age << endl;
    }
    // 成员形式的操作符函数  万能指针是必要的      万能引用是必要的
//    Human operator+( /* const Human* this */ const Human& that ) const {
//        return Human(this->m_age+that.m_age, (this->m_name+"+"+that.m_name).c_str());
//    }
private:
    int m_age;
    string m_name;
    friend Human operator+( const Human& l, const Human& r ) ; // 友元声明
};
// 全局形式的操作符函数
Human operator+( const Human& l, const Human& r ) { 
    return Human(l.m_age+r.m_age, (l.m_name+"+"+r.m_name).c_str() );
}
// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Human a(22,"张飞"), b(20,"赵云"); // 非常左值
    const Human c(25,"关羽"), d(32,"马超"); // 常左值

    Human res =  a + b; // ==> a.operator+(b)  或  operator+(a,b)
    res.getinfo( );
    
    res = c + d; // ==> c.operator+(d)  或  operator+(c,d)
    res.getinfo();

    res= Human(45,"黄忠")+ Human(35,"刘备");//Human(45,"黄忠").operator+(Human(35,"刘备"))
                                         //operator+( Human(45,"黄忠"), Human(35,"刘备"))
    res.getinfo();
    /*
    int a=10, b=20; // 非常左值
    const int c=30, d=40; // 常左值

    |30| a + b;
    a + c;
    a + 5;
    c + b;
    5 + b;
    */
    return 0;
}

3.2  赋值类  =  +=  -=  *=  /=  等

        左操作数必须为非常左值 

        右操作数可以为非常左值常左值右值 

        表达式结果为左操作数本身(而非副本)

        operator=()就是拷贝赋值函数,编译器会默认给。

// double_operator2.cpp
#include <iostream>
using namespace std;

class Human { // 授权类(授予朋友权利的类)
public:
    Human( int age=0, const char* name="无名" ) : m_age(age),m_name(name) {
        //【int m_age=age;】
        //【string m_name(name);】
    }
    void getinfo( ) {
        cout << "姓名: " << m_name << ", 年龄: " << m_age << endl;
    }
    // 成员形式的操作符函数
    Human& operator+=( /* Human* this */ const Human& that ) {
        this->m_age = this->m_age + that.m_age;
        this->m_name = this->m_name+"+"+that.m_name;
        return *this;
    }
private:
    int m_age;
    string m_name;
};
// 全局形式的操作符函数(自己课下写)

// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Human a(22,"张飞"), b(20,"赵云"); // 非常左值
    const Human c(25,"关羽"), d(32,"马超"); // 常左值

    ((a+=b)+=c)+=Human(45,"黄忠");
    a.getinfo();
    /*
    a += b; // a.operator+=(b)  或  operator+=(a,b)
    a.getinfo();

    a += c; // a.operator+=(c)  或  operator+=(a,c)
    a.getinfo();

    a += Human(45,"黄忠"); //   a.operator+=(Human(45,"黄忠")) 
                          // 或 operator+=(a,Human(45,"黄忠"))
    a.getinfo();
    */

    /*
    int a=10, b=20; // 非常左值
    const int c=30, d=40; // 常左值

    a = b; 
    a = c;
    a = 5;
    c = b; // error
    5 = b; // error
    */
    return 0;
}

3.3  比较类   >   <   ==   <=   >=   等

        左操作数为非常左值常左值右值 

        右操作数为非常左值常左值右值

        表达式结果为bool 

// double_operator3.cpp
#include <iostream>
using namespace std;

class Human { // 授权类(授予朋友权利的类)
public:
    Human( int age=0, const char* name="无名" ) : m_age(age),m_name(name) {
        //【int m_age=age;】
        //【string m_name(name);】
    }
    void getinfo( ) {
        cout << "姓名: " << m_name << ", 年龄: " << m_age << endl;
    }
    // 成员形式的操作符函数
    bool operator==( /* const Human* this */ const Human& that ) const {
        return this->m_age==that.m_age && this->m_name==that.m_name;
    }
    bool operator!=( /* const Human* this */ const Human& that ) const {
//      return this->m_age!=that.m_age || this->m_name!=that.m_name;
        return !(*this==that);
    }
private:
    int m_age;
    string m_name;
};
// 全局形式的操作符函数(自己课下写)

// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Human a(22,"张飞"), b(20,"赵云"); // 非常左值
    const Human c(25,"关羽"), d(32,"马超"); // 常左值

    cout << (a == b) << endl; // a.operator==(b)  或 ...
    cout << (a != b) << endl; // a.operator!=(b)  或 ...

    cout << (c == d) << endl; // c.operator==(d)  或 ...
    cout << (c != d) << endl; // c.operator!=(d)  或 ...

    cout << (Human(45,"黄忠")==Human(35,"刘备")) << endl; 
                              // Human(45,"黄忠").operator==(Human(35,"刘备"))
    cout << (Human(45,"黄忠")!=Human(35,"刘备")) << endl; 
                              // Human(45,"黄忠").operator!=(Human(35,"刘备"))

    /*
    int a=10, b=20; // 非常左值
    const int c=30, d=40; // 常左值

    a == b;
    a == c;
    a == 5;
    c == b;
    5 == b;

    */
    return 0;
}

4  典型单目操作符

4.1  运算类  -    ~    !   等

        操作数为非常左值常左值右值 

        表达式的结果为右值 

// single_operator1.cpp
#include <iostream>
using namespace std;

class Human { // 授权类(授予朋友权利的类)
public:
    Human( int age=0, const char* name="无名" ) : m_age(age),m_name(name) {
        //【int m_age=age;】
        //【string m_name(name);】
    }
    void getinfo( ) {
        cout << "姓名: " << m_name << ", 年龄: " << m_age << endl;
    }
    // 成员形式的操作符函数
    Human operator-( /* const Human* this */ ) const  {
        return Human(-this->m_age, ("-"+this->m_name).c_str() );
    }
private:
    int m_age;
    string m_name;
};
// 全局形式的操作符函数(自己课下写)

// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Human a(22,"张飞"), b(20,"赵云"); // 非常左值
    const Human c(25,"关羽"), d(32,"马超"); // 常左值

    Human res = -a; // a.operator-()  或 ... 
    res.getinfo();

    res = -c; // c.operator-()  或 ...
    res.getinfo();

    res = -Human(45,"黄忠"); // Human(45,"黄忠").operator-()  或 ...
    res.getinfo();

    /*
    int a=10, b=20; // 非常左值
    const int c=30, d=40; // 常左值

    |-10| -a; // ok
    |-30| -c; // ok
    |-40| -40;// ok
    */
    return 0;
}

4.2  前自增减类  ++O  --O

        操作数为非常左值 

        表达式结果为操作数本身(而非副本)

4.3  后自增减类  O++  O--

        操作数为非常左值 

        表达式的结果为右值,且为自增减以前的值

// single_operator2.cpp
#include <iostream>
using namespace std;

class Human { // 授权类(授予朋友权利的类)
public:
    Human( int age=0, const char* name="无名" ) : m_age(age),m_name(name) {
        //【int m_age=age;】
        //【string m_name(name);】
    }
    void getinfo( ) {
        cout << "姓名: " << m_name << ", 年龄: " << m_age << endl;
    }
    // 成员形式的操作符函数
    Human& operator++( /* Human* this */ ) {
        this->m_age += 1; // 直接就加1
        return *this;
    }
    Human operator++( /* Human* this */ int ) {
        Human old = *this; // 克隆一份b原来的值
        this->m_age += 1; // 直接就加1
        return old; // 返回的为克隆的b原来的值
    } 
private:
    int m_age;
    string m_name;
};
// 全局形式的操作符函数(自己课下写)

// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Human a(22,"张飞"), b(20,"赵云"); // 非常左值
    const Human c(25,"关羽"), d(32,"马超"); // 常左值

    (++a).getinfo(); // a.operator++()  或  operator++(a)

    (/*|...|*/b++).getinfo(); // b.operator++(0) 或  operator++(b,0) 
    b.getinfo();
    /*
    int a=10, b=20; // 非常左值
    const int c=30, d=40; // 常左值

    ++a; // ok
    ++c; // error
    ++5; // error

    b++; // ok
    c++; // error
    5++; // error
    */
    return 0;
}

5  其他操作符

5.1  输出流操作符  <<

        左操作数(cout)为  非常左值  形式的输出流( ostream )对象

        右操作数为  左值或右值

        表达式的结果为左操作符本身(而非副本)

        

        左操作数的类型为ostream,

        (若以成员函数形式重载该操作符,就应将其定义为ostream类的成员),

        但该类为标准库提供,无法添加新的成员,因此只能以全局函数形式重载该操作符:

        ostream&  operator<< ( ostream& os,  const RTGHT& right ) { ... } 

5.2  输入流操作符  >>

        左操作数为  非常左值  形式的输入流( istream )对象

        右操作数为  非常左值 

        表达式的结果为左操作符本身(而非副本)

        左操作数的类型为istream,

        (若以成员函数形式重载该操作符,就应将其定义为istream类的成员),

        但该类为标准库提供,无法添加新的成员,因此只能以全局函数形式重载该操作符:

        istream&  operator>> ( istream& is,  RIGHT& right ) { ... } 

// io.cpp
#include <iostream>
using namespace std;

class Human { 
public:
    Human( int age=0, const char* name="无名" ) : m_age(age),m_name(name) {
        //【int m_age=age;】
        //【string m_name(name);】
    }
    void getinfo( ) {
        cout << "姓名: " << m_name << ", 年龄: " << m_age << endl;
    }
private:
    int m_age;
    string m_name;
    friend ostream& operator<<( ostream& os, const Human& that ) ;
    friend istream& operator>>( istream& is, Human& that ) ;
};
// 全局形式的操作符函数(自己课下写)
ostream& operator<<( ostream& os, const Human& that ) {
    os << "姓名:" << that.m_name << ", 年龄:" << that.m_age;
    return os;
}
istream& operator>>( istream& is, Human& that ) {
    is >> that.m_name >> that.m_age;
    return is; 
}
// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Human a(22,"张飞"), b(20,"赵云"); // 非常左值
    const Human c(25,"关羽"), d(32,"马超"); // 常左值

//    a.getinfo();
    cout << a << endl; // operator<<(cout, a)
    cout << c << endl; // operator<<(cout, c)
    cout << Human(45,"黄忠") << endl; // operator<<(cout, Human(45,"黄忠") )

    cin >> a; //  operator>>(cin,a)
    cout << a << endl;

    /*
     
    int a=10, b=20; // 非常左值
    const int c=30, d=40; // 常左值

    cout << a;
    cout << c;
    cout << 5;

    */
    return 0;
}

5.3  下标操作符  []

        一般用于在容器类型中以下标方式获取数据元素

        非常容器的元素为非常左值

        常容器的元素为常左值

// stack.cpp 
// 简易的栈容器 -- 先进后出
#include <iostream>
using namespace std;

class Stack {
public:
    Stack() : m_s(0) {
        //【int arr[20];】
        //【int m_s=0;】
    }
    void push(int data) {  arr[m_s++] = data; } // 判满操作,自己课下写
    int pop() { return arr[--m_s];  } // 判空操作,自己课下写
    int size() {  return m_s; }
    const int& operator[]( /* const Stack* this */ size_t i) const { // 常函数
        return this->arr[i];
    }
    int& operator[]( /* Stack* this */ size_t i) { // 非常函数
        return this->arr[i];
    }
private:
    int arr[20]; // 保存数据
    int m_s;     // 保存数据个数
};

// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Stack s; // 非常容器
    for( int i=0; i<20; i++ ) {
        s.push( 1000+i );
    }
    cout << "压栈后s容器中数据的个数:" << s.size() << endl;
    s[5] = 888; // 非常容器的元素,就是非常左值   s.operator[](5)=888
    for( int i=0; i<20; i++ ) {
        cout << s[i] << ' ';
    }
    cout << endl;
    cout << "读数据后s容器中数据的个数:" << s.size() << endl;

    const Stack cs = s; // cs是常容器
    cs[5] = 999; // cs.operator[](5)=999    应该让编译器报readonly错误
    
    /*
    int s[20] = {...}; // s是非常容器,s的元素就是非常左值
    s[5] = 888;

    const int cs[20] = {...}; // cs是常容器,cs的元素就是常左值
    cs[5] = 999; // 报告readonly错误
    */
    return 0;
}

5.4  类型转换操作符

        1)若源类型是基本类型,目标类型是类型,则

        只能通过类型转换 构造 函数实现自定义类型转换:

                class 目标类型 {

                        目标类型 ( const 源类型& src ) {...}

                };

        2)若源类型是类型,目标类型是基本类型,则

        只能通过类型转换 操作符 函数实现自定义类型转换:

                class 源类型 {

                        operator 目标类型 (void) const {...}

                };

        3)若源类型和目标类型都是类型,则

        既优先通过类型转换 构造 函数,其次通过类型转换 操作符 函数实现自定义类型转换。

        但两者没必要同时使用。

        4)若源类型和目标类型都是基本类型,则

        无法实现自定义类型转换,基本类型之间的转换规则是由编译器内置的隐式转换。

// cast1.cpp
// 类型转换构造函数 和 类型转换操作符函数
#include <iostream>
using namespace std;
class Integer {
public:
    Integer(int i):m_i(i) {
        //【int m_i=i;】
        cout << "Integer类的类型转换构造函数被调用" << endl;
    }
    operator int( /* const Integer* this */ ) const {
        cout << "Integer类的类型转换操作符函数被调用" << endl;
        return this->m_i;
    }
private:
    int m_i;
};
// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    int m = 100;
    
    // int-->Integer (基本类型-->类类型)
    Integer ix = m; // 定义 匿名Integer类对象,利用 匿名Integer类对象.Integer(m)
                       ->类型转换构造函数
                    // Integer ix = m.operator Integer()
                       -->int类中绝对没有一个operator Integer成员函数(走不通)

    // Integer-->int (类类型-->基本类型)
    int n = ix; 
    // 定义 匿名int类对象,利用 匿名int类对象.int(ix)
       -->int类中绝对没有一个形参为Integer的构造函数(走不通)
    // int n = ix.operator int() --> 类型转换操作符函数
    return 0;
}
// cast2.cpp
// 类型转换构造函数/类型转换操作符函数 -- 指定 源类型 到 目标类型 的 转换规则
#include <iostream>
using namespace std;
class Dog; // 短式声明
class Cat {
public:
    Cat( const char* name ) : m_name(name) { 
        //【string m_name(name);】
    }
    void talk( ) {
        cout << m_name << ": 喵喵~~~" << endl;
    }
    operator Dog( /* const Cat* this */ ) const; // 声明
private:
    string m_name;
    friend class Dog; // 友元声明
};

class Dog {
public:
    Dog( const char* name ) : m_name(name) {
        //【string m_name(name);】
    }
    Dog( const Cat& c ) : m_name(c.m_name) { //类型转换构造函数(Cat-->Dog的转换规则)
        //【string m_name=c.m_name;】
        cout << "Dog类的类型转换构造函数被调用" << endl;
    }
    void talk( ) {
        cout << m_name << ": 汪汪~~~" << endl;
    }
private:
    string m_name;
};
Cat::operator Dog( /* const Cat* this */ ) const { // 定义
    cout << "Cat类的类型转换操作符函数被调用" << endl;
    return Dog( this->m_name.c_str() );
}
// 模拟类的设计者(类库、别人设计的类、自己设计的类)
// --------------------------------
// 模拟用户(使用类的人)
int main( void ) {
    Cat smallwhite("小白"); 
    // Cat-->Dog (类类型-->类类型)
    Dog bigyellow = smallwhite; //定义 匿名Dog类对象,利用 匿名Dog类对象.Dog(smallwhite)
                                   ->类型转换构造函数 
                                //Dog bigyellow = smallwhite.operator Dog()
                                   ->类型转换操作符函数
    return 0;
}

6  操作符重载的局限

        1)不是所有的操作符都能重载,以下操作符就不能重载:

                作用域限定操作符        ::  

                直接成员访问操作符        .  

                条件操作符        ? :  

                字节长度操作符        sizeof  

                类型信息操作符        typeid  

        2)所有操作数均为基本类型的操作符也不能重载:

                1 + 1 = 8 ?

7  友元

        可以通过friend关键字,把

        一个全局函数、另一个类的成员函数、另一个整体,

        声明为授权类的友元。

        友元拥有访问授权类任何非公有成员的特权。(即访问所有成员)

        友元声明可以出现在授权类的公有、私有、保护等任何区域,且不受  访问控制限定符  的约束。

        友元是成员,其作用域并隶属于授权类,也拥有授权类类型的this指针。

// twoDimensional_08.cpp 设计一个二维坐标系的 类
#include <iostream>
using namespace std;

class TwoDimensional {
public:
    TwoDimensional( int x=0, int y=0 ) {
        // 在this指向的内存空间中 定义m_x初值为随机数
        // 在this指向的内存空间中 定义m_y初值为随机数
        m_x = x;
        m_y = y;
    }
    TwoDimensional operator+( /* const TwoDimensional* this */ const TwoDimensional& that ) const {
        return TwoDimensional( this->m_x+that.m_x, this->m_y+that.m_y );
    }
    TwoDimensional& operator=( /* TwoDimensional* this */ const TwoDimensional& that ) {
        this->m_x = that.m_x;
        this->m_y = that.m_y;
        return *this;
    }
    bool operator>( /* const TwoDimensional* this */ const TwoDimensional& that ) const {
        return this->m_x*this->m_x+this->m_y*this->m_y > that.m_x*that.m_x + that.m_y*that.m_y;
    }
    TwoDimensional operator-( /* const TwoDimensional* this */ ) const {
        return TwoDimensional( -this->m_x, -this->m_y );
    }
    TwoDimensional& operator++( /* TwoDimensional& this*/ ) {
        ++this->m_x;
        ++this->m_y;
        return *this;
    }
private:
    int m_x; // 横坐标
    int m_y; // 纵坐标
    friend ostream& operator<<( ostream& os, const TwoDimensional& that );
};
ostream& operator<<( ostream& os, const TwoDimensional& that ) {
    os << "横坐标:" << that.m_x << ", 纵坐标:" << that.m_y;
    return os;
}

class ThreeDimensional {
public:
    ThreeDimensional( int x=0, int y=0, int z=0 ) : m_x(x),m_y(y),m_z(z) {}
    operator TwoDimensional( /* const ThreeDimensional* this */ ) const {
        return TwoDimensional( this->m_x, this->m_y );
    }
private:
    int m_x;
    int m_y;
    int m_z;
};
int main( void ) {
    TwoDimensional a(1,2), b(3,4);

    cout << "a-->" << a  << ", b-->" << b << endl; // cout 打印 坐标对象
    
    TwoDimensional res = a + b; // 坐标间求和
    cout << res << endl;
    a = b; // 坐标间赋值
    cout << a << endl;
    cout << (a > b) << endl; // 坐标间比较大小
    res = -a; // 坐标取反
    cout << res << endl;
    cout << ++a << endl; // 坐标自增

    ThreeDimensional c(100,200,300);

    TwoDimensional d = c; // TwoDimensional d = c.operator TwoDimensional();
    cout << d << endl;
    return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/284750.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Origin绘制频数分布直方图+曲线拟合分布

问题描述 有组数据大概分布如下&#xff0c;现在想在Origin中绘制出以下效果 流程 如果我们想要人为每个柱子的边界&#xff0c;以方便展示&#xff0c;需要新建一列&#xff0c;输入数据分布的大概区间。 需要注意的是&#xff0c;C(Y)列中删除数据时若留下的“-”符合存…

鸿蒙开发第1篇__网络请求

先访问 OpenAtom OpenHarmony &#xff0c; 浏览 Http数据请求&#xff0c;

CSS 缩减顶部动画

<template><!-- mouseenter"startAnimation" 表示在鼠标进入元素时触发 startAnimation 方法。mouseleave"stopAnimation" 表示在鼠标离开元素时触发 stopAnimation 方法。 --><!-- 容器元素 --><div class"container" mou…

Linux:apache优化(7)—— 日志分割|日志合并

作用&#xff1a;随着网站访问量的增加&#xff0c;访问日志中的信息会越来越多&#xff0c; Apache 默认访问日志access_log单个文件会越来越大&#xff0c;日志文件体积越大&#xff0c;信息都在一个文件中&#xff0c;查看及分析信息会及不方便。 分割 实现方式&#xff1a…

【java爬虫】使用element-plus进行个股详细数据分页展示

前言 前面的文章我们讲述了获取详细个股数据的方法&#xff0c;并且使用echarts对个股的价格走势图进行了展示&#xff0c;本文将编写一个页面&#xff0c;对个股详细数据进行展示。别问涉及到了element-plus中分页的写法&#xff0c;对于这部分知识将会做重点讲解。 首先看一…

【SpringBoot开发】之商城项目案例(实现登陆版)

&#x1f389;&#x1f389;欢迎来到我的CSDN主页&#xff01;&#x1f389;&#x1f389; &#x1f3c5;我是君易--鑨&#xff0c;一个在CSDN分享笔记的博主。&#x1f4da;&#x1f4da; &#x1f31f;推荐给大家我的博客专栏《SpringBoot开发之商城项目系列》。&#x1f3af…

【NLP论文】02 TF-IDF 关键词权值计算

之前写了一篇关于关键词词库构建的文章&#xff0c;没想到反响还不错&#xff0c;最近有空把接下来的两篇补完&#xff0c;也继续使用物流关键词词库举例&#xff0c;本篇文章承接关键词词库构建并以其为基础&#xff0c;将计算各关键词的 TF-IDF 权值&#xff0c;TF-IDF 权值主…

霹雳吧啦Wz《pytorch图像分类》-p2AlexNet网络

《pytorch图像分类》p2AlexNet网络基础及代码 一、零碎知识点1.过拟合2.使用dropout后的正向传播3.正则化regularization4.代码中所用的知识点 二、总体架构分析1.ReLU激活函数2.手算3.模型代码 三、训练花分类课程代码1.model.py2.train.py3.predict.py 一、零碎知识点 1.过拟…

FPGA项目(14)——基于FPGA的数字秒表设计

1.功能设计 设计内容及要求: 1.秒表最大计时范围为99分59. 99秒 2.6位数码管显示&#xff0c;分辨率为0.01秒 3.具有清零、启动计时、暂停及继续计时等功能 4.控制操作按键不超过二个。 2.设计思路 所采用的时钟为50M&#xff0c;先对时钟进行分频&#xff0c;得到100HZ频率…

【Maven】下载配置maven以及IDEA配置maven详情

目录 1、下载maven 2、配置settings.xml 2.1、配置本地仓库 2.2、配置阿里云镜像仓库 2.3、配置JDK 3、配置环境变量 4、IDEA配置maven 1、下载maven maven官网&#xff1a;https://maven.apache.org/ 2、配置settings.xml 2.1、配置本地仓库 <localRepository>C:\…

oracle 9i10g编程艺术-读书笔记1

根据书中提供的下载代码链接地址&#xff0c;从github上找到源代码下载地址。 https://github.com/apress下载好代码后&#xff0c;开始一段新的旅行。 设置 SQL*Plus 的 AUTOTRACE 设置 SQL*Plus 的 AUTOTRACE AUTOTRACE 是 SQL*Plus 中一个工具&#xff0c;可以显示所执行…

GPT4-AIl本地部署-chat AI本地使用

文章目录 GPT4-AIl本地部署GPT4客户端下载地址&#xff1a;对应的下载下载后的文件点击安装&#xff0c;改一下文件存放路径&#xff0c;下面都是默认下一步进度条100%后&#xff0c;点击完成 安装完桌面生成图标&#xff0c;点击选择都是NO&#xff0c;不进行数据上传点击后&a…

Python编程新技能:如何优雅地实现水仙花数?

水仙花数&#xff08;Narcissistic number&#xff09;也被称为阿姆斯特朗数&#xff08;Armstrong number&#xff09;或自恋数等&#xff0c;它是一个非负整数&#xff0c;其特性是该数的每个位上的数字的n次幂之和等于它本身&#xff0c;其中n是该数的位数。简单来说&#x…

一起学Elasticsearch系列-写入原理

本文已收录至Github&#xff0c;推荐阅读 &#x1f449; Java随想录 微信公众号&#xff1a;Java随想录 文章目录 写入过程写操作写流程写一致性策略 写入原理RefreshMergeFlushTranslog图解写入流程 ES作为一款开源的分布式搜索和分析引擎&#xff0c;以其卓越的性能和灵活的扩…

29 UVM Command Line Processor (CLP)

随着设计和验证环境的复杂性增加&#xff0c;编译时间也增加了&#xff0c;这也影响了验证时间。因此&#xff0c;需要对其进行优化&#xff0c;以便在不强制重新编译的情况下考虑新的配置或参数。我们已经看到了function or task如何基于传递参数进行行为。类似地&#xff0c;…

均方差损失推导

一、损失函数&#xff08;Cost function&#xff09; 定义&#xff1a;用于衡量模型预测结果与真实结果之间差距的函数。&#xff08;有的地方称之为代价函数&#xff0c;但是个人感觉损失函数这个名称更贴近实际用途&#xff09; 理解&#xff1a;&#xff08;以均方差损失函…

Python浪漫520表白代码

系列文章 序号文章目录直达链接表白系列1浪漫520表白代码https://want595.blog.csdn.net/article/details/1306668812满屏飘字表白代码https://want595.blog.csdn.net/article/details/1349149703无限弹窗表白代码https://want595.blog.csdn.net/article/details/1297945184跳…

使用.Net nanoFramework 驱动ESP32的OLED显示屏

本文介绍如何使用.Net nanoFramework 驱动ESP32的OLED显示屏。我们将会从最基础的部分开始&#xff0c;逐步深入&#xff0c;让你能够理解并实现整个过程。无论你是初学者还是有一定经验的开发者&#xff0c;这篇文章都会对你有所帮助。 1. 硬件准备 1.1 ESP32开发板 这里我们…

搭建flink集群 —— 筑梦之路

Apache Flink 是一个框架和分布式处理引擎&#xff0c; 用于在无边界和有边界数据流上进行有状态的计算。 Flink 能在所有常见集群环境中运行&#xff0c;并能以内存速度和任意规模进行计算。 Flink并没有依靠自身实现所有分布式系统需要解决的问题&#xff0c; 而是在已有集群…

c语言之将输入的十进制转换成二进制数并打印原码反码补码

十进制转二进制 首先&#xff0c;我们要知道的是十进制转换成二进制数的方法。我们一般采用的除二取余的方法&#xff0c;在这里我用32位数组来进行转换。 int main() {printf("请输入一个十进制数\n");int n 0;scanf("%d", &n);int arr[32];int* p…