Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
cpp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edu
cpp
Commits
49f35bdd
Commit
49f35bdd
authored
Nov 19, 2020
by
Hans Buchmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
copy constructor
numer of constructor calls == numer of destructor calls
parent
5a6815e6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
6-cia/src/geo2d-vz.cc
6-cia/src/geo2d-vz.cc
+30
-4
No files found.
6-cia/src/geo2d-vz.cc
View file @
49f35bdd
...
...
@@ -13,7 +13,8 @@ class Point
public:
Point
(
double
x
,
double
y
);
//constructor x/y position in the plane
//non default constructor
~
Point
();
//destructor no parameters
Point
(
const
Point
&
other
);
//copy constructor
~
Point
();
//destructor no parameters
double
distance
(
Point
other
);
static
double
distance
(
Point
p
,
Point
q
);
...
...
@@ -32,6 +33,12 @@ Point::Point(double x,double y) //x,y parameter
std
::
cout
<<
"constructor of Point "
<<
xc
<<
","
<<
yc
<<
"
\n
"
;
}
Point
::
Point
(
const
Point
&
other
)
:
xc
(
other
.
xc
),
yc
(
other
.
yc
)
{
std
::
cout
<<
"copy constructor of Point "
<<
xc
<<
","
<<
yc
<<
"
\n
"
;
}
Point
::~
Point
()
{
std
::
cout
<<
"destructor of Point "
<<
xc
<<
","
<<
yc
<<
"
\n
"
;
...
...
@@ -47,10 +54,30 @@ double Point::distance(Point other) //is a member of Point
{
return
std
::
hypot
(
xc
-
other
.
xc
,
yc
-
other
.
yc
);
}
}
//destructor of other
//---------------------------------------------- Line
/*
constructor of Point 3,4 p
constructor of Point 6,8 q
destructor of Point 6,8 other
d=5
destructor of Point 6,8 q
destructor of Point 3,4 p
*/
/* with own copy constructor
constructor of Point 3,4 p
constructor of Point 6,8 q
copy constructor of Point 6,8 other
destructor of Point 6,8 other
d=5
destructor of Point 6,8 q
destructor of Point 3,4 p
*/
int
main
(
int
argc
,
char
**
args
)
{
Point
p
(
3
,
4
);
...
...
@@ -58,8 +85,7 @@ int main(int argc,char**args)
/*
distance (3,4) -> (6,8) = sqrt(3*3+4*4)=sqrt(25)=5
*/
auto
d0
=
Point
::
distance
(
p
,
q
);
//with static
auto
d1
=
p
.
distance
(
q
);
//non static
auto
d1
=
p
.
distance
(
q
);
std
::
cout
<<
"d="
<<
d1
<<
"
\n
"
;
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment