1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include <iostream>
using namespace std;
class Student { public: Student() : m_age(0), m_name("") { cout << "Student()" << endl; }
Student(int age) : m_age(age), m_name("") { cout << "Student(int)" << endl; }
Student(int age, string name) : m_age(age), m_name(name) { cout << "Student(int, string)" << endl; }
Student(const Student& s) { cout << "Student(const Student &)" << endl; }
~Student() { cout << "~Student" << endl; }
int getAge() const { return m_age; }
string getName() const { return m_name; }
void show() const { cout << "age: " << m_age << ", name: " << m_name << endl; }
private: int m_age; string m_name; };
void print(Student stu) { cout << "age: " << stu.getAge() << ", name: " << stu.getName() << endl; }
int main() { Student student1 = 20;
Student student2 = (12, 13, 14, 15);
print(25);
return 0; }
|