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
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
732 additions
and
0 deletions
+732
-0
BM-GJB8114-2013/R-1-9-2/R-1-9-2-bad.cpp
BM-GJB8114-2013/R-1-9-2/R-1-9-2-bad.cpp
+11
-0
BM-GJB8114-2013/R-1-9-3/R-1-9-3-bad.c
BM-GJB8114-2013/R-1-9-3/R-1-9-3-bad.c
+15
-0
BM-GJB8114-2013/R-1-9-3/R-1-9-3-bad.cpp
BM-GJB8114-2013/R-1-9-3/R-1-9-3-bad.cpp
+15
-0
BM-GJB8114-2013/R-1-9-4/R-1-9-4-bad.c
BM-GJB8114-2013/R-1-9-4/R-1-9-4-bad.c
+16
-0
BM-GJB8114-2013/R-1-9-4/R-1-9-4-bad.cpp
BM-GJB8114-2013/R-1-9-4/R-1-9-4-bad.cpp
+16
-0
BM-GJB8114-2013/R-1-9-4/R-1-9-4-good.c
BM-GJB8114-2013/R-1-9-4/R-1-9-4-good.c
+16
-0
BM-GJB8114-2013/R-1-9-4/R-1-9-4-good.cpp
BM-GJB8114-2013/R-1-9-4/R-1-9-4-good.cpp
+16
-0
BM-GJB8114-2013/R-2-1-2/R-2-1-2-bad.cpp
BM-GJB8114-2013/R-2-1-2/R-2-1-2-bad.cpp
+54
-0
BM-GJB8114-2013/R-2-1-2/R-2-1-2-good.cpp
BM-GJB8114-2013/R-2-1-2/R-2-1-2-good.cpp
+54
-0
BM-GJB8114-2013/R-2-1-3/R-2-1-3-bad.cpp
BM-GJB8114-2013/R-2-1-3/R-2-1-3-bad.cpp
+74
-0
BM-GJB8114-2013/R-2-1-3/R-2-1-3-good.cpp
BM-GJB8114-2013/R-2-1-3/R-2-1-3-good.cpp
+74
-0
BM-GJB8114-2013/R-2-1-4/R-2-1-4-bad.cpp
BM-GJB8114-2013/R-2-1-4/R-2-1-4-bad.cpp
+59
-0
BM-GJB8114-2013/R-2-1-4/R-2-1-4-good.cpp
BM-GJB8114-2013/R-2-1-4/R-2-1-4-good.cpp
+60
-0
BM-GJB8114-2013/R-2-2-1/R-2-2-1-bad.cpp
BM-GJB8114-2013/R-2-2-1/R-2-2-1-bad.cpp
+28
-0
BM-GJB8114-2013/R-2-2-1/R-2-2-1-good.cpp
BM-GJB8114-2013/R-2-2-1/R-2-2-1-good.cpp
+33
-0
BM-GJB8114-2013/R-2-2-2/R-2-2-2-bad.cpp
BM-GJB8114-2013/R-2-2-2/R-2-2-2-bad.cpp
+28
-0
BM-GJB8114-2013/R-2-2-2/R-2-2-2-good.cpp
BM-GJB8114-2013/R-2-2-2/R-2-2-2-good.cpp
+33
-0
BM-GJB8114-2013/R-2-2-3/R-2-2-3-bad.cpp
BM-GJB8114-2013/R-2-2-3/R-2-2-3-bad.cpp
+49
-0
BM-GJB8114-2013/R-2-2-3/R-2-2-3-good.cpp
BM-GJB8114-2013/R-2-2-3/R-2-2-3-good.cpp
+53
-0
BM-GJB8114-2013/R-2-2-4/R-2-2-4-bad.cpp
BM-GJB8114-2013/R-2-2-4/R-2-2-4-bad.cpp
+28
-0
No files found.
BM-GJB8114-2013/R-1-9-2/R-1-9-2-bad.cpp
0 → 100644
View file @
2a291a73
int
main
(
void
)
{
float
f
=
0.0
,
g
=
1.0
;
for
(
f
=
0.0
;
f
<
10.0
;
f
=
f
+
1.0
)
//违背1
{
g
=
f
+
g
;
}
return
(
0
);
}
BM-GJB8114-2013/R-1-9-3/R-1-9-3-bad.c
0 → 100644
View file @
2a291a73
int
main
(
void
)
{
int
i
,
j
,
k
;
j
=
100
;
k
=
0
;
for
(
i
=
0
;
i
<
j
;
i
++
)
{
i
=
2
*
i
;
//违背1
k
=
k
+
1
;
}
return
(
0
);
}
BM-GJB8114-2013/R-1-9-3/R-1-9-3-bad.cpp
0 → 100644
View file @
2a291a73
int
main
(
void
)
{
int
i
,
j
,
k
;
j
=
100
;
k
=
0
;
for
(
i
=
0
;
i
<
j
;
i
++
)
{
i
=
2
*
i
;
//违背1
k
=
k
+
1
;
}
return
(
0
);
}
BM-GJB8114-2013/R-1-9-4/R-1-9-4-bad.c
0 → 100644
View file @
2a291a73
int
Gstatic
=
0
;
int
main
(
void
)
{
for
(
;
;
)
//违背1
{
//...
if
(
1
==
Gstatic
)
{
break
;
}
}
return
(
0
);
}
BM-GJB8114-2013/R-1-9-4/R-1-9-4-bad.cpp
0 → 100644
View file @
2a291a73
int
Gstatic
=
0
;
int
main
(
void
)
{
for
(
;
;
)
//违背1
{
//...
if
(
1
==
Gstatic
)
{
break
;
}
}
return
(
0
);
}
BM-GJB8114-2013/R-1-9-4/R-1-9-4-good.c
0 → 100644
View file @
2a291a73
int
Gstatic
=
0
;
int
main
(
void
)
{
while
(
1
)
//遵循1
{
//...
if
(
1
==
Gstatic
)
{
break
;
}
}
return
(
0
);
}
BM-GJB8114-2013/R-1-9-4/R-1-9-4-good.cpp
0 → 100644
View file @
2a291a73
int
Gstatic
=
0
;
int
main
(
void
)
{
while
(
1
)
//遵循1
{
//...
if
(
1
==
Gstatic
)
{
break
;
}
}
return
(
0
);
}
BM-GJB8114-2013/R-2-1-2/R-2-1-2-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
B
{
public:
B
(
void
);
virtual
~
B
(
void
);
virtual
int
g
(
int
a
=
0
);
private:
int
b
;
};
B
::
B
(
void
)
:
b
(
1
)
{
}
B
::~
B
(
void
)
{
}
int
B
::
g
(
int
a
)
{
return
(
a
+
b
);
}
class
D
:
public
virtual
B
{
public:
D
(
void
);
virtual
~
D
(
void
);
virtual
int
g
(
int
a
=
0
);
private:
int
d
;
};
D
::
D
(
void
)
:
B
(
),
d
(
2
)
{
}
D
::~
D
(
void
)
{
}
int
D
::
g
(
int
a
)
{
return
(
a
+
d
);
}
int
main
(
void
)
{
D
d
;
B
&
b
=
d
;
B
*
pb
=
&
d
;
D
*
pd1
=
reinterpret_cast
<
D
*
>
(
pb
);
//违背1
D
&
pd2
=
reinterpret_cast
<
D
&
>
(
*
pb
);
//违背2
return
(
0
);
}
BM-GJB8114-2013/R-2-1-2/R-2-1-2-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
B
{
public:
B
(
void
);
virtual
~
B
(
void
);
virtual
int
g
(
int
a
=
0
);
private:
int
b
;
};
B
::
B
(
void
)
:
b
(
1
)
{
}
B
::~
B
(
void
)
{
}
int
B
::
g
(
int
a
)
{
return
(
a
+
b
);
}
class
D
:
public
virtual
B
{
public:
D
(
void
);
virtual
~
D
(
void
);
virtual
int
g
(
int
a
=
0
);
private:
int
d
;
};
D
::
D
(
void
)
:
B
(
),
d
(
2
)
{
}
D
::~
D
(
void
)
{
}
int
D
::
g
(
int
a
)
{
return
(
a
+
d
);
}
int
main
(
void
)
{
D
d
;
B
&
b
=
d
;
B
*
pb
=
&
d
;
D
*
pd1
=
dynamic_cast
<
D
*
>
(
pb
);
//遵循1
D
&
pd2
=
dynamic_cast
<
D
&
>
(
*
pb
);
//遵循2
return
(
0
);
}
BM-GJB8114-2013/R-2-1-3/R-2-1-3-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
A
{
public:
A
(
void
);
void
SetA
(
int
);
private:
int
a
;
};
A
::
A
(
void
)
:
a
(
0
)
{
}
void
A
::
SetA
(
int
va
)
{
a
=
va
;
}
class
B1
:
public
A
//违背1
{
public:
B1
(
void
);
void
SetB1
(
int
);
private:
int
b1
;
};
B1
::
B1
(
void
)
:
A
(
),
b1
(
0
)
{
}
void
B1
::
SetB1
(
int
vb
)
{
b1
=
vb
;
SetA
(
b1
+
1
);
}
class
B2
:
public
A
//违背2
{
public:
B2
(
void
);
void
SetB2
(
int
);
private:
int
b2
;
};
B2
::
B2
(
void
)
:
A
(
),
b2
(
0
)
{
}
void
B2
::
SetB2
(
int
vb
)
{
b2
=
vb
;
SetA
(
b2
+
2
);
}
class
D
:
public
B1
,
public
B2
{
public:
D
(
void
);
private:
int
d
;
};
D
::
D
(
void
)
:
B1
(
),
B2
(
),
d
(
0
)
{
}
int
main
(
void
)
{
D
thed
;
thed
.
SetB1
(
1
);
thed
.
SetB2
(
2
);
return
(
0
);
}
BM-GJB8114-2013/R-2-1-3/R-2-1-3-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
A
{
public:
A
(
void
);
void
SetA
(
int
);
private:
int
a
;
};
A
::
A
(
void
)
:
a
(
0
)
{
}
void
A
::
SetA
(
int
va
)
{
a
=
va
;
}
class
B1
:
public
virtual
A
//遵循1
{
public:
B1
(
void
);
void
SetB1
(
int
);
private:
int
b1
;
};
B1
::
B1
(
void
)
:
A
(
),
b1
(
0
)
{
}
void
B1
::
SetB1
(
int
vb
)
{
b1
=
vb
;
SetA
(
b1
+
1
);
}
class
B2
:
public
virtual
A
//遵循2
{
public:
B2
(
void
);
void
SetB2
(
int
);
private:
int
b2
;
};
B2
::
B2
(
void
)
:
A
(
),
b2
(
0
)
{
}
void
B2
::
SetB2
(
int
vb
)
{
b2
=
vb
;
SetA
(
b2
+
2
);
}
class
D
:
public
B1
,
public
B2
{
public:
D
(
void
);
private:
int
d
;
};
D
::
D
(
void
)
:
B1
(
),
B2
(
),
d
(
0
)
{
}
int
main
(
void
)
{
D
thed
;
thed
.
SetB1
(
1
);
thed
.
SetB2
(
2
);
return
(
0
);
}
BM-GJB8114-2013/R-2-1-4/R-2-1-4-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
B
{
public:
B
(
void
);
virtual
~
B
(
void
);
virtual
void
f
(
void
)
=
0
;
B
&
operator
=
(
B
const
&
rhs
);
//违背1
private:
int
kind
;
};
B
::
B
(
void
)
:
kind
(
0
)
{
}
B
::~
B
(
void
)
{
}
B
&
B
::
operator
=
(
B
const
&
rhs
)
{
kind
=
rhs
.
kind
;
return
(
*
this
);
}
class
D
:
public
B
{
public:
D
(
void
);
virtual
~
D
(
void
);
virtual
void
f
(
void
)
{
};
D
&
operator
=
(
D
const
&
rhs
);
private:
int
member
;
};
D
::
D
(
void
)
:
B
(
),
member
(
0
)
{
}
D
::~
D
(
void
)
{
}
D
&
D
::
operator
=
(
D
const
&
rhs
)
{
member
=
rhs
.
member
;
return
(
*
this
);
}
int
main
(
void
)
{
D
d1
;
D
d2
;
B
&
b1
=
d1
;
B
&
b2
=
d2
;
b1
=
b2
;
//违背2
return
(
0
);
}
BM-GJB8114-2013/R-2-1-4/R-2-1-4-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
B
{
public:
B
(
void
);
virtual
~
B
(
void
);
virtual
void
f
(
void
)
=
0
;
protected:
B
&
operator
=
(
B
const
&
rhs
);
//遵循1
private:
int
kind
;
};
B
::
B
(
void
)
:
kind
(
0
)
{
}
B
::~
B
(
void
)
{
}
B
&
B
::
operator
=
(
B
const
&
rhs
)
{
kind
=
rhs
.
kind
;
return
(
*
this
);
}
class
D
:
public
B
{
public:
D
(
void
);
virtual
~
D
(
void
);
virtual
void
f
(
void
)
{
};
D
&
operator
=
(
D
const
&
rhs
);
private:
int
member
;
};
D
::
D
(
void
)
:
B
(
),
member
(
0
)
{
}
D
::~
D
(
void
)
{
}
D
&
D
::
operator
=
(
D
const
&
rhs
)
{
member
=
rhs
.
member
;
return
(
*
this
);
}
int
main
(
void
)
{
D
d1
;
D
d2
;
B
&
b1
=
d1
;
B
&
b2
=
d2
;
b1
=
b2
;
//由于采取了保护,此用法被禁止,编译报错
return
(
0
);
}
BM-GJB8114-2013/R-2-2-1/R-2-2-1-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
int
gVar
=
10
;
class
Foo
{
public:
Foo
(
void
);
~
Foo
(
void
);
private:
int
a
;
};
Foo
::
Foo
(
void
)
{
a
=
gVar
;
//违背1
}
Foo
::~
Foo
(
void
)
{
}
int
main
(
void
)
{
Foo
thef
;
return
(
0
);
}
BM-GJB8114-2013/R-2-2-1/R-2-2-1-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
int
gVar
=
10
;
class
Foo
{
public:
Foo
(
void
);
explicit
Foo
(
int
);
~
Foo
(
void
);
private:
int
a
;
};
Foo
::
Foo
(
void
)
{
a
=
0
;
}
Foo
::
Foo
(
int
var
)
{
a
=
var
;
}
Foo
::~
Foo
(
void
)
{
}
int
main
(
void
)
{
Foo
thef
(
gVar
);
//遵循1
return
(
0
);
}
BM-GJB8114-2013/R-2-2-2/R-2-2-2-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Foo
//违背1
{
public:
~
Foo
(
void
);
void
SetVer
(
int
);
private:
int
a
;
};
Foo
::~
Foo
(
void
)
{
}
void
Foo
::
SetVer
(
int
var
)
{
a
=
var
;
}
int
main
(
void
)
{
Foo
thef
;
thef
.
SetVer
(
2
);
return
(
0
);
}
BM-GJB8114-2013/R-2-2-2/R-2-2-2-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Foo
{
public:
Foo
(
void
);
//遵循1
~
Foo
(
void
);
void
SetVer
(
int
);
private:
int
a
;
};
Foo
::
Foo
(
void
)
{
a
=
0
;
}
Foo
::~
Foo
(
void
)
{
}
void
Foo
::
SetVer
(
int
var
)
{
a
=
var
;
}
int
main
(
void
)
{
Foo
thef
;
thef
.
SetVer
(
2
);
return
(
0
);
}
BM-GJB8114-2013/R-2-2-3/R-2-2-3-bad.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Foo
{
public:
Foo
(
void
);
Foo
(
int
var
);
//违背1
int
getVar
(
void
);
~
Foo
(
void
);
private:
int
a
;
};
Foo
::
Foo
(
void
)
{
a
=
0
;
}
Foo
::
Foo
(
int
var
)
{
a
=
var
;
}
int
Foo
::
getVar
(
void
)
{
return
a
;
}
Foo
::~
Foo
(
void
)
{
}
void
f
(
Foo
);
int
main
(
void
)
{
int
i
=
1
;
f
(
i
);
return
(
0
);
}
void
f
(
Foo
thef
)
{
int
j
;
//...
j
=
thef
.
getVar
(
);
}
BM-GJB8114-2013/R-2-2-3/R-2-2-3-good.cpp
0 → 100644
View file @
2a291a73
#include <iostream>
using
namespace
std
;
class
Foo
{
public:
Foo
(
void
);
explicit
Foo
(
int
var
);
//遵循1
int
getVar
(
void
);
~
Foo
(
void
);
private:
int
a
;
};
Foo
::
Foo
(
void
)
{
a
=
0
;
}
Foo
::
Foo
(
int
var
)
{
a
=
var
;
}
int
Foo
::
getVar
(
void
)
{
return
a
;
}
Foo
::~
Foo
(
void
)
{
}
void
f
(
int
);
int
main
(
void
)
{
Foo
thef
(
1
);
int
i
=
1
;
f
(
i
);
return
(
0
);
}
void
f
(
int
i
)
{
int
j
;
Foo
thef
(
1
);
//...
j
=
thef
.
getVar
(
);
}
BM-GJB8114-2013/R-2-2-4/R-2-2-4-bad.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
;
}
Foo
::
Foo
(
int
varb
)
//违背2
{
b
=
varb
;
}
int
main
(
void
)
{
Foo
thef1
,
thef2
(
1
);
return
(
0
);
}
Prev
1
…
18
19
20
21
22
23
24
25
26
…
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