Hỏi về tác dụng của dấu ":" trong lệnh "Student(int x):Person(x)"

Chỗ này là gì vậy ạ?
Student(int x):Person(x)

#include<iostream> 
using namespace std; 
class Person { 
public: 
	Person(int x) { cout << "Person::Person(int ) called" << endl; } 
	Person()	 { cout << "Person::Person() called" << endl; } 
}; 

class Faculty : virtual public Person { 
public: 
	Faculty(int x):Person(x) { 
	cout<<"Faculty::Faculty(int ) called"<< endl; 
	} 
}; 

class Student : virtual public Person { 
public: 
	Student(int x):Person(x) { 
		cout<<"Student::Student(int ) called"<< endl; 
	} 
}; 

class TA : public Faculty, public Student { 
public: 
	TA(int x):Student(x), Faculty(x) { 
		cout<<"TA::TA(int ) called"<< endl; 
	} 
}; 

int main() { 
	TA ta1(30); 
}

Gọi hàm dựng của lớp cha.
Bạn chạy thì trình tự in ra bạn sẽ biết nó gọi đến đâu mà.

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?