Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abfd1c3

Browse files
committed
cPlusLearn
1 parent 0c99631 commit abfd1c3

File tree

7 files changed

+112
-1
lines changed

7 files changed

+112
-1
lines changed

CppShk.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
FCD7C9E528BCF1BA0074E82B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FCD7C9E428BCF1BA0074E82B /* main.cpp */; };
11+
FCE0F50928C0C7B00036C39A /* Functionptr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FCE0F50728C0C7B00036C39A /* Functionptr.cpp */; };
1112
/* End PBXBuildFile section */
1213

1314
/* Begin PBXCopyFilesBuildPhase section */
@@ -25,6 +26,8 @@
2526
/* Begin PBXFileReference section */
2627
FCD7C9E128BCF1BA0074E82B /* CppShk */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CppShk; sourceTree = BUILT_PRODUCTS_DIR; };
2728
FCD7C9E428BCF1BA0074E82B /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
29+
FCE0F50728C0C7B00036C39A /* Functionptr.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Functionptr.cpp; sourceTree = "<group>"; };
30+
FCE0F50828C0C7B00036C39A /* Functionptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Functionptr.hpp; sourceTree = "<group>"; };
2831
/* End PBXFileReference section */
2932

3033
/* Begin PBXFrameworksBuildPhase section */
@@ -57,6 +60,8 @@
5760
FCD7C9E328BCF1BA0074E82B /* CppShk */ = {
5861
isa = PBXGroup;
5962
children = (
63+
FCE0F50728C0C7B00036C39A /* Functionptr.cpp */,
64+
FCE0F50828C0C7B00036C39A /* Functionptr.hpp */,
6065
FCD7C9E428BCF1BA0074E82B /* main.cpp */,
6166
);
6267
path = CppShk;
@@ -119,6 +124,7 @@
119124
isa = PBXSourcesBuildPhase;
120125
buildActionMask = 2147483647;
121126
files = (
127+
FCE0F50928C0C7B00036C39A /* Functionptr.cpp in Sources */,
122128
FCD7C9E528BCF1BA0074E82B /* main.cpp in Sources */,
123129
);
124130
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>PreviewsEnabled</key>
6+
<false/>
7+
</dict>
8+
</plist>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>BuildLocationStyle</key>
6+
<string>UseAppPreferences</string>
7+
<key>CustomBuildLocationType</key>
8+
<string>RelativeToDerivedData</string>
9+
<key>DerivedDataLocationStyle</key>
10+
<string>Default</string>
11+
<key>IssueFilterStyle</key>
12+
<string>ShowActiveSchemeOnly</string>
13+
<key>LiveSourceIssuesEnabled</key>
14+
<true/>
15+
<key>ShowSharedSchemesAutomaticallyEnabled</key>
16+
<true/>
17+
</dict>
18+
</plist>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
uuid = "65C71704-DD73-48DB-9A02-CECFA2687288"
4+
type = "1"
5+
version = "2.0">
6+
</Bucket>

CppShk/Functionptr.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Functionptr.cpp
3+
// CppShk
4+
//
5+
// Created by 孙海洋 on 2022/9/1.
6+
//
7+
8+
#include "Functionptr.hpp"
9+
#include<iostream>
10+
11+
double Rick(int lines)
12+
{
13+
return lines * 0.05;
14+
}
15+
16+
void estimate(int lines, double (*pf)(int))
17+
{
18+
std::cout << "您的代码大概用时:" << (*pf)(lines) << std::endl;
19+
}
20+
21+
void p1(int n)
22+
{
23+
std::cout << "这是p1" << std::endl;
24+
}
25+
26+
void p2(int n)
27+
{
28+
std::cout << "这是p2" << std::endl;
29+
}
30+
31+
void p3(int n)
32+
{
33+
std::cout << "这是p3" << std::endl;
34+
}
35+

CppShk/Functionptr.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Functionptr.hpp
3+
// CppShk
4+
//
5+
// Created by 孙海洋 on 2022/9/1.
6+
//
7+
8+
#ifndef Functionptr_hpp
9+
#define Functionptr_hpp
10+
11+
#include <stdio.h>
12+
double Rick(int lines);
13+
void estimate(int lines, double (*pf)(int));
14+
15+
void p1(int n);
16+
void p2(int n);
17+
void p3(int n);
18+
19+
20+
#endif /* Functionptr_hpp */

CppShk/main.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,27 @@
66
//
77

88
#include <iostream>
9+
#include"Functionptr.hpp"
10+
using namespace std;
911

1012
int main(int argc, const char * argv[]) {
1113
// insert code here...
12-
std::cout << "Hello, World!\n";
14+
estimate(100, *Rick);
15+
16+
//这个用typedef才能够更好的理解
17+
typedef void(* Fuc)(int);
18+
Fuc ptr[3] = { p1, p2, p3};
19+
for(auto n : ptr)
20+
{
21+
n(1);
22+
}
23+
24+
25+
// auto ptr = { p1, p2, p3};
26+
// auto itrater = ptr.begin();
27+
// while (itrater != ptr.end()) {
28+
// (*itrater)(1);
29+
// itrater++;
30+
// }
1331
return 0;
1432
}

0 commit comments

Comments
 (0)