support bazel complie this project and format code.
This commit is contained in:
15
basic_content/friend/BUILD
Normal file
15
basic_content/friend/BUILD
Normal file
@@ -0,0 +1,15 @@
|
||||
# please run `bazel run basic_content/friend:friend_class`
|
||||
# please run `bazel run basic_content/friend:friend_func`
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
||||
|
||||
cc_binary(
|
||||
name = "friend_class",
|
||||
srcs = ["friend_class.cpp"],
|
||||
copts = ["-std=c++11"]
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "friend_func",
|
||||
srcs = ["friend_func.cpp"],
|
||||
copts = ["-std=c++11"]
|
||||
)
|
Binary file not shown.
@@ -2,27 +2,23 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class A
|
||||
{
|
||||
class A {
|
||||
public:
|
||||
A(int _a):a(_a){};
|
||||
friend class B;
|
||||
A(int _a) : a(_a){};
|
||||
friend class B;
|
||||
|
||||
private:
|
||||
int a;
|
||||
int a;
|
||||
};
|
||||
|
||||
class B
|
||||
{
|
||||
class B {
|
||||
public:
|
||||
int getb(A ca) {
|
||||
return ca.a;
|
||||
};
|
||||
int getb(A ca) { return ca.a; };
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
A a(3);
|
||||
B b;
|
||||
cout<<b.getb(a)<<endl;
|
||||
return 0;
|
||||
int main() {
|
||||
A a(3);
|
||||
B b;
|
||||
cout << b.getb(a) << endl;
|
||||
return 0;
|
||||
}
|
||||
|
Binary file not shown.
@@ -1,33 +1,20 @@
|
||||
/**
|
||||
* @file friend_func.cpp
|
||||
* @brief 友元函数
|
||||
* @author 光城
|
||||
* @version v1
|
||||
* @date 2019-08-06
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class A
|
||||
{
|
||||
class A {
|
||||
public:
|
||||
A(int _a):a(_a){};
|
||||
friend int geta(A &ca); ///< 友元函数
|
||||
A(int _a) : a(_a){};
|
||||
friend int geta(A &ca); ///< 友元函数
|
||||
private:
|
||||
int a;
|
||||
int a;
|
||||
};
|
||||
|
||||
int geta(A &ca)
|
||||
{
|
||||
return ca.a;
|
||||
}
|
||||
int geta(A &ca) { return ca.a; }
|
||||
|
||||
int main()
|
||||
{
|
||||
A a(3);
|
||||
cout<<geta(a)<<endl;
|
||||
int main() {
|
||||
A a(3);
|
||||
cout << geta(a) << endl;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user