Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Administrator
Public Cpp Test
Commits
2a291a73
Commit
2a291a73
authored
Oct 23, 2023
by
shengnan hu
Browse files
main
parents
Changes
638
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
816 additions
and
0 deletions
+816
-0
BM-GJB8114-2013/R-2-2-4/R-2-2-4-good.cpp
BM-GJB8114-2013/R-2-2-4/R-2-2-4-good.cpp
+30
-0
BM-GJB8114-2013/R-2-2-5/R-2-2-5-bad.cpp
BM-GJB8114-2013/R-2-2-5/R-2-2-5-bad.cpp
+33
-0
BM-GJB8114-2013/R-2-2-5/R-2-2-5-good.cpp
BM-GJB8114-2013/R-2-2-5/R-2-2-5-good.cpp
+33
-0
BM-GJB8114-2013/R-2-3-1/R-2-3-1-bad.cpp
BM-GJB8114-2013/R-2-3-1/R-2-3-1-bad.cpp
+56
-0
BM-GJB8114-2013/R-2-3-1/R-2-3-1-good.cpp
BM-GJB8114-2013/R-2-3-1/R-2-3-1-good.cpp
+56
-0
BM-GJB8114-2013/R-2-3-2/R-2-3-2-bad.cpp
BM-GJB8114-2013/R-2-3-2/R-2-3-2-bad.cpp
+36
-0
BM-GJB8114-2013/R-2-3-2/R-2-3-2-good.cpp
BM-GJB8114-2013/R-2-3-2/R-2-3-2-good.cpp
+43
-0
BM-GJB8114-2013/R-2-4-1/R-2-4-1-bad.cpp
BM-GJB8114-2013/R-2-4-1/R-2-4-1-bad.cpp
+51
-0
BM-GJB8114-2013/R-2-4-1/R-2-4-1-good.cpp
BM-GJB8114-2013/R-2-4-1/R-2-4-1-good.cpp
+63
-0
BM-GJB8114-2013/R-2-4-2/R-2-4-2-bad.cpp
BM-GJB8114-2013/R-2-4-2/R-2-4-2-bad.cpp
+51
-0
BM-GJB8114-2013/R-2-4-2/R-2-4-2-good.cpp
BM-GJB8114-2013/R-2-4-2/R-2-4-2-good.cpp
+51
-0
BM-GJB8114-2013/R-2-4-3/R-2-4-3-bad.cpp
BM-GJB8114-2013/R-2-4-3/R-2-4-3-bad.cpp
+57
-0
BM-GJB8114-2013/R-2-5-1/R-2-5-1-bad.cpp
BM-GJB8114-2013/R-2-5-1/R-2-5-1-bad.cpp
+41
-0
BM-GJB8114-2013/R-2-5-2/R-2-5-2-bad.cpp
BM-GJB8114-2013/R-2-5-2/R-2-5-2-bad.cpp
+38
-0
BM-GJB8114-2013/R-2-6-1/R-2-6-1-bad.cpp
BM-GJB8114-2013/R-2-6-1/R-2-6-1-bad.cpp
+31
-0
BM-GJB8114-2013/R-2-6-1/R-2-6-1-good.cpp
BM-GJB8114-2013/R-2-6-1/R-2-6-1-good.cpp
+33
-0
BM-GJB8114-2013/R-2-6-2/R-2-6-2-bad.cpp
BM-GJB8114-2013/R-2-6-2/R-2-6-2-bad.cpp
+21
-0
BM-GJB8114-2013/R-2-6-2/R-2-6-2-good.cpp
BM-GJB8114-2013/R-2-6-2/R-2-6-2-good.cpp
+21
-0
BM-GJB8114-2013/R-2-6-3/R-2-6-3-bad.cpp
BM-GJB8114-2013/R-2-6-3/R-2-6-3-bad.cpp
+35
-0
BM-GJB8114-2013/R-2-6-3/R-2-6-3-good.cpp
BM-GJB8114-2013/R-2-6-3/R-2-6-3-good.cpp
+36
-0
No files found.
BM-GJB8114-2013/R-2-2-4/R-2-2-4-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Foo
{
public:
int
a
;
Foo
(
void
);
explicit
Foo
(
int
);
private:
int
b
;
};
Foo
::
Foo
(
void
)
//遵循1
{
a
=
0
;
b
=
0
;
}
Foo
::
Foo
(
int
varb
)
//遵循2
{
a
=
0
;
b
=
varb
;
}
int
main
(
void
)
{
Foo
thef1
,
thef2
(
1
);
return
(
0
);
}
BM-GJB8114-2013/R-2-2-5/R-2-2-5-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Docement
{
public:
int
docid
;
Docement
(
void
)
:
docid
(
0
)
{
}
explicit
Docement
(
int
);
};
Docement
::
Docement
(
int
var
)
{
docid
=
var
;
}
class
Book
:
public
Docement
{
public:
int
bookid
;
Book
(
void
)
:
bookid
(
1
)
//违背1
{
}
};
int
main
(
void
)
{
Book
mybook
;
return
(
0
);
}
BM-GJB8114-2013/R-2-2-5/R-2-2-5-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Docement
{
public:
int
docid
;
Docement
(
void
)
:
docid
(
0
)
{
}
explicit
Docement
(
int
);
};
Docement
::
Docement
(
int
var
)
{
docid
=
var
;
}
class
Book
:
public
Docement
{
public:
int
bookid
;
Book
(
void
)
:
Document
(
1
),
bookid
(
1
)
//遵循1
{
}
};
int
main
(
void
)
{
Book
mybook
;
return
(
0
);
}
BM-GJB8114-2013/R-2-3-1/R-2-3-1-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
B
{
public:
B
(
void
);
~
B
(
void
);
//违背1
virtual
void
f
(
int
a
)
=
0
;
protected:
B
(
const
B
&
);
B
&
operator
=
(
const
B
&
);
};
B
::
B
(
void
)
{
}
B
::~
B
(
void
)
{
}
class
D
:
public
B
{
public:
D
(
void
);
explicit
D
(
int
a
);
~
D
(
void
);
//违背2
virtual
void
f
(
int
a
);
private:
int
*
md
;
D
(
const
D
&
);
D
&
operator
=
(
const
D
&
);
};
D
::
D
(
int
a
)
:
B
(
),
md
(
new
int
)
{
*
md
=
a
;
}
void
D
::
f
(
int
a
)
{
*
md
=
a
;
}
D
::~
D
(
void
)
{
delete
md
;
md
=
NULL
;
}
int
main
(
void
)
{
B
*
d
=
new
D
(
1
);
d
->
f
(
2
);
delete
d
;
d
=
NULL
;
return
(
0
);
}
BM-GJB8114-2013/R-2-3-1/R-2-3-1-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
B
{
public:
B
(
void
);
virtual
~
B
(
void
);
//遵循1
virtual
void
f
(
int
a
)
=
0
;
protected:
B
(
const
B
&
);
B
&
operator
=
(
const
B
&
);
};
B
::
B
(
void
)
{
}
B
::~
B
(
void
)
{
}
class
D
:
public
B
{
public:
D
(
void
);
explicit
D
(
int
a
);
virtual
~
D
(
void
);
//遵循2
virtual
void
f
(
int
a
);
private:
int
*
md
;
D
(
const
D
&
);
D
&
operator
=
(
const
D
&
);
};
D
::
D
(
int
a
)
:
B
(
),
md
(
new
int
)
{
*
md
=
a
;
}
void
D
::
f
(
int
a
)
{
*
md
=
a
;
}
D
::~
D
(
void
)
{
delete
md
;
md
=
NULL
;
}
int
main
(
void
)
{
B
*
d
=
new
D
(
1
);
d
->
f
(
2
);
delete
d
;
d
=
NULL
;
return
(
0
);
}
BM-GJB8114-2013/R-2-3-2/R-2-3-2-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Foo
{
public:
int
a
;
Foo
(
void
);
~
Foo
(
void
);
};
Foo
::
Foo
(
void
)
{
a
=
1
;
}
Foo
::~
Foo
(
void
)
{
if
(
1
==
a
)
{
throw
0
;
}
//违背1
}
int
main
(
void
)
{
try
{
Foo
f
;
}
catch
(
int
e
)
{
//......
}
return
(
0
);
}
BM-GJB8114-2013/R-2-3-2/R-2-3-2-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Foo
{
public:
int
a
;
Foo
(
void
);
~
Foo
(
void
);
};
Foo
::
Foo
(
void
)
{
a
=
1
;
}
Foo
::~
Foo
(
void
)
{
try
{
if
(
1
==
a
)
{
throw
0
;
}
}
catch
(
int
e
)
//遵循1
{
//......
}
}
int
main
(
void
)
{
try
{
Foo
f
;
}
catch
(
int
e
)
{
//......
}
return
(
0
);
}
BM-GJB8114-2013/R-2-4-1/R-2-4-1-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Base
{
public:
Base
(
void
);
virtual
~
Base
(
void
);
virtual
int
g
(
int
a
=
0
);
};
Base
::
Base
(
void
)
{
}
Base
::~
Base
(
void
)
{
}
int
Base
::
g
(
int
a
)
{
return
(
a
+
1
);
}
class
Derived
:
public
virtual
Base
{
public:
Derived
(
void
);
virtual
~
Derived
(
void
);
virtual
int
g
(
int
a
=
1
);
//违背1
};
Derived
::
Derived
(
void
)
{
}
Derived
::~
Derived
(
void
)
{
}
int
Derived
::
g
(
int
a
)
{
return
(
a
+
11
);
}
int
main
(
void
)
{
int
i
;
Derived
d
;
Base
&
b
=
d
;
i
=
b
.
g
(
);
i
=
d
.
g
(
);
return
(
0
);
}
BM-GJB8114-2013/R-2-4-1/R-2-4-1-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Base
{
public:
Base
(
void
);
virtual
~
Base
(
void
);
virtual
int
g1
(
int
a
=
0
);
virtual
int
g2
(
int
a
=
0
);
};
Base
::
Base
(
void
)
{
}
Base
::~
Base
(
void
)
{
}
int
Base
::
g1
(
int
a
)
{
return
(
a
+
1
);
}
int
Base
::
g2
(
int
a
)
{
return
(
a
+
2
);
}
class
Derived
:
public
Base
{
public:
Derived
(
void
);
virtual
~
Derived
(
void
);
virtual
int
g1
(
int
a
=
0
);
//遵循1
virtual
int
g2
(
int
a
);
//遵循2
};
Derived
::
Derived
(
void
)
{
}
Derived
::~
Derived
(
void
)
{
}
int
Derived
::
g1
(
int
a
)
{
return
(
a
+
11
);
}
int
Derived
::
g2
(
int
a
)
{
return
(
a
+
12
);
}
int
main
(
void
)
{
int
i
,
j
;
Derived
d
;
Base
&
b
=
d
;
i
=
b
.
g1
(
);
i
=
d
.
g1
(
);
j
=
b
.
g2
(
);
j
=
d
.
g2
(
0
);
return
(
0
);
}
BM-GJB8114-2013/R-2-4-2/R-2-4-2-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Base
{
public:
Base
(
void
);
virtual
~
Base
(
void
);
virtual
int
g
(
int
a
=
0
);
};
Base
::
Base
(
void
)
{
}
Base
::~
Base
(
void
)
{
}
int
Base
::
g
(
int
a
)
{
return
(
a
+
1
);
}
class
Derived
:
public
Base
{
public:
Derived
(
void
);
virtual
~
Derived
(
void
);
int
g
(
int
a
=
0
);
//违背1
};
Derived
::
Derived
(
void
)
{
}
Derived
::~
Derived
(
void
)
{
}
int
Derived
::
g
(
int
a
)
{
return
(
a
+
2
);
}
int
main
(
void
)
{
int
i
,
j
;
Derived
d
;
Base
&
b
=
d
;
i
=
b
.
g
(
);
j
=
d
.
g
(
);
return
(
0
);
}
BM-GJB8114-2013/R-2-4-2/R-2-4-2-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Base
{
public:
Base
(
void
);
virtual
~
Base
(
void
);
virtual
int
g
(
int
a
=
0
);
};
Base
::
Base
(
void
)
{
}
Base
::~
Base
(
void
)
{
}
int
Base
::
g
(
int
a
)
{
return
(
a
+
1
);
}
class
Derived
:
public
Base
{
public:
Derived
(
void
);
virtual
~
Derived
(
void
);
virtual
int
g
(
int
a
=
0
);
//遵循1
};
Derived
::
Derived
(
void
)
{
}
Derived
::~
Derived
(
void
)
{
}
int
Derived
::
g
(
int
a
)
{
return
(
a
+
2
);
}
int
main
(
void
)
{
int
i
,
j
;
Derived
d
;
Base
&
b
=
d
;
i
=
b
.
g
(
);
j
=
d
.
g
(
);
return
(
0
);
}
BM-GJB8114-2013/R-2-4-3/R-2-4-3-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
A
{
public:
A
(
void
);
virtual
~
A
(
void
);
virtual
void
foo
(
void
)
=
0
;
};
A
::
A
(
void
)
{
}
A
::~
A
(
void
)
{
}
class
B
:
public
A
{
public:
B
(
void
);
virtual
~
B
(
void
);
virtual
void
foo
(
void
);
};
B
::
B
(
void
)
{
}
B
::~
B
(
void
)
{
}
void
B
::
foo
(
void
)
{
}
class
C
:
public
B
{
public:
C
(
void
);
virtual
~
C
(
void
);
virtual
void
foo
(
void
)
=
0
;
//违背1
};
C
::
C
(
void
)
{
}
C
::~
C
(
void
)
{
}
int
main
(
void
)
{
B
myb
;
myb
.
foo
(
);
return
(
0
);
}
BM-GJB8114-2013/R-2-5-1/R-2-5-1-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
struct
S
{
int
i
;
int
j
;
int
k
;
};
class
C
{
public:
int
i
;
int
j
;
int
k
;
C
(
void
);
virtual
~
C
(
void
);
};
C
::
C
(
void
)
:
i
(
0
),
j
(
0
),
k
(
0
)
{
}
C
::~
C
(
void
)
{
}
int
main
(
void
)
{
S
*
s
=
new
S
;
s
->
i
=
0
;
s
->
j
=
0
;
s
->
k
=
0
;
C
*
c
=
reinterpret_cast
<
C
*
>
(
s
);
//违背1
//...
return
(
0
);
}
BM-GJB8114-2013/R-2-5-2/R-2-5-2-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
A
{
public:
A
(
void
);
~
A
(
void
);
explicit
A
(
int
);
int
ma
;
};
A
::
A
(
void
)
{
ma
=
0
;
}
A
::
A
(
int
a
)
{
ma
=
a
;
}
A
::~
A
(
void
)
{
}
int
main
(
void
)
{
A
const
a1
=
A
(
10
);
A
*
a2
=
const_cast
<
A
*
>
(
&
a1
);
//违背1
a2
->
ma
=
11
;
A
&
a3
=
const_cast
<
A
&
>
(
a1
);
//违背2
a3
.
ma
=
12
;
return
(
0
);
}
BM-GJB8114-2013/R-2-6-1/R-2-6-1-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
void
fun1
(
void
)
{
int
*
p
=
new
int
;
//违背1
*
p
=
1
;
//......
}
void
fun2
(
void
)
{
int
*
p
=
new
int
[
3
];
//违背2
p
[
0
]
=
1
;
p
[
1
]
=
2
;
p
[
2
]
=
3
;
//......
}
int
main
(
void
)
{
fun1
(
);
fun2
(
);
return
(
0
);
}
BM-GJB8114-2013/R-2-6-1/R-2-6-1-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
void
fun1
(
void
)
{
int
*
p
=
new
int
;
*
p
=
1
;
delete
p
;
//遵循1
p
=
NULL
;
}
void
fun2
(
void
)
{
int
*
p
=
new
int
[
3
];
p
[
0
]
=
1
;
p
[
1
]
=
2
;
p
[
2
]
=
3
;
delete
[
]
p
;
//遵循2
p
=
NULL
;
}
int
main
(
void
)
{
fun1
(
);
fun2
(
);
return
(
0
);
}
BM-GJB8114-2013/R-2-6-2/R-2-6-2-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
void
fun
(
void
)
{
int
*
p
=
new
int
[
3
];
p
[
0
]
=
1
;
p
[
1
]
=
2
;
p
[
2
]
=
3
;
delete
p
;
//违背1
p
=
NULL
;
}
int
main
(
void
)
{
fun
(
);
return
(
0
);
}
BM-GJB8114-2013/R-2-6-2/R-2-6-2-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
void
fun
(
void
)
{
int
*
p
=
new
int
[
3
];
p
[
0
]
=
1
;
p
[
1
]
=
2
;
p
[
2
]
=
3
;
delete
[
]
p
;
//遵循1
p
=
NULL
;
}
int
main
(
void
)
{
fun
(
);
return
(
0
);
}
BM-GJB8114-2013/R-2-6-3/R-2-6-3-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
int
fun
(
void
);
int
main
(
void
)
{
int
i
;
i
=
fun
(
);
return
(
0
);
}
int
fun
(
void
)
{
int
*
p
=
new
int
[
3
];
if
(
NULL
==
p
)
{
return
(
-
1
);
}
else
{
*
p
=
1
;
p
++
;
*
p
=
2
;
delete
[
]
p
;
//违背1
p
=
NULL
;
}
return
(
0
);
}
BM-GJB8114-2013/R-2-6-3/R-2-6-3-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
int
fun
(
void
);
int
main
(
void
)
{
int
i
;
i
=
fun
(
);
return
(
0
);
}
int
fun
(
void
)
{
int
*
p
=
new
int
[
3
];
int
*
pbak
=
p
;
if
(
NULL
==
p
)
{
return
(
-
1
);
}
else
{
*
p
=
1
;
p
++
;
*
p
=
2
;
delete
[
]
pbak
;
//遵循1
pbak
=
NULL
;
}
return
(
0
);
}
Prev
1
…
19
20
21
22
23
24
25
26
27
…
32
Next
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