Issue
I am not able to understand the syntax of
class_name: class_ptr_1(nullptr), class_ptr_2(nullptr) {}
Solution
It seems you mean
class_name() : class_ptr_1(nullptr), class_ptr_2(nullptr) {}
^^^
It is a constructor definition with a mem-initializer list. That is the class data members class_ptr_1
and class_ptr_2
are initialized in the mem-initializer list.
Here is an example
#include <iostream>
#include <string>
struct Beginner
{
Beginner() : first_name( "Deepak" ), last_name( "Singh" )
{
}
std::string first_name;
std::string last_name;
};
int main()
{
Beginner beginner;
std::cout << "first name: " << beginner.first_name
<< ", last name: " << beginner.last_name
<< '\n';
}
The program output is
first name: Deepak, last name: Singh
Answered By - Vlad from Moscow Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.