Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
2
2024ustc-jianmu-compiler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Analytics
Analytics
CI / CD
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
compiler_staff
2024ustc-jianmu-compiler
Commits
0db19a25
Commit
0db19a25
authored
Sep 01, 2024
by
刘睿博
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
093a32f0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
8 deletions
+19
-8
include/Human.hpp
include/Human.hpp
+1
-1
include/Student.hpp
include/Student.hpp
+2
-1
src/Human.cpp
src/Human.cpp
+7
-3
src/Student.cpp
src/Student.cpp
+9
-3
No files found.
include/Human.hpp
View file @
0db19a25
...
...
@@ -9,6 +9,6 @@ private:
public:
explicit
Human
(
int
age
,
const
std
::
string
name
=
""
)
:
name_
(
name
),
age_
(
age
)
{};
virtual
~
Human
();
virtual
char
*
print
()
const
;
virtual
std
::
string
print
()
const
;
};
include/Student.hpp
View file @
0db19a25
#pragma once
#include "Human.hpp"
#include <string>
class
Student
:
public
Human
{
...
...
@@ -11,5 +12,5 @@ public:
Student
()
=
delete
;
explicit
Student
(
int
age
,
const
std
::
string
name
=
""
,
const
std
::
string
school
=
""
)
:
Human
(
age
,
name
),
school_
(
school
)
{};
virtual
~
Student
()
override
;
virtual
char
*
print
()
const
override
;
virtual
std
::
string
print
()
const
override
;
};
\ No newline at end of file
src/Human.cpp
View file @
0db19a25
#include "Human.hpp"
#include <string>
#include <sstream>
Human
::~
Human
()
{
printf
(
"Human destructor called
\n
"
);
}
char
*
Human
::
print
()
const
{
char
*
res
=
new
char
[
100
];
sprintf
(
res
,
"My name is %s and I am %d years old
\n
"
,
name_
.
c_str
(),
age_
);
std
::
string
Human
::
print
()
const
{
std
::
string
res
;
std
::
stringstream
ss
;
ss
<<
"My name is "
<<
name_
<<
" and I am "
<<
age_
<<
" years old
\n
"
;
ss
>>
res
;
return
res
;
}
\ No newline at end of file
src/Student.cpp
View file @
0db19a25
#include "Student.hpp"
#include "Human.hpp"
#include "cstring"
#include <sstream>
#include <string>
Student
::~
Student
()
{
printf
(
"Student destructor called
\n
"
);
}
char
*
Student
::
print
()
const
{
char
*
res
=
Human
::
print
();
sprintf
(
res
+
strlen
(
res
),
"I'm from %s
\n
"
,
school_
.
c_str
());
std
::
string
Student
::
print
()
const
{
std
::
string
res
;
std
::
stringstream
ss
;
ss
<<
Human
::
print
();
ss
<<
"I'm from "
<<
school_
<<
"
\n
"
;
ss
>>
res
;
return
res
;
}
\ No newline at end of file
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