构造函数作为友元函数的参数

#include<iostream>
using namespace std;
class A
{
public:
    friend void test(A a);
    int a1;
    A()
    {
        cout<<"A"<<" ";
    }

};
    void test(A a)
    {
        a.a1=1;
        cout<<a.a1<<" ";
    }


int main()
{
    test(A());
    return 0;
}

image

构造函数无返回值,但调用它会创建一个对象,

原文地址:https://www.cnblogs.com/lzh-Linux/p/3482808.html