Mình có đọc được đoạn này:
“Constructors are for initializing data fields. The data field radius does not have an initial
value, so it must be initialized in the constructor (lines 13 and 19 in Listing 9.1). Note that a
variable (local or global) can be declared and initialized in one statement, but as a class member, a data field cannot be initialized when it is declared.”
nhưng khi mình test thì nó vẫn chạy ok mà.
class Constructor {
private:
int radius = 4;
public:
void toString(){
std::cout << "radius is: " << this->radius << std::endl;
}
};
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?