Answer the question
In order to leave comments, you need to log in
Is it possible to call a function from a C++ class constructor?
Hi all!
The question is, is it possible to call a function from a class constructor? those. without calling a function from main. More or less like this:
// Конструктор Students
Students::Students(std::string name, std::string last_name)
{
Students::set_name(name); // Вызываем(создаем) функцию с фактическим параметром
Students::set_last_name(last_name); // тоже самое. Можно ли так делать?
}
Answer the question
In order to leave comments, you need to log in
is it possible to call a function from a class constructor?
Students::Students(std::string name, std::string last_name) { Students::set_name(name); // Вызываем(создаем) функцию с фактическим параметром Students::set_last_name(last_name); // тоже самое. Можно ли так делать? }
class Students
{
...
std::string name_;
std::string last_name_;
...
};
Students::Students(const std::string& name, const std::string& last_name): name_(name), last_name_(last_name)
{
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question