In C++, anything done with a member function can also be done by a free-standing function
Though sometimes there may be an advantage of one over the other this process is doable and converting from one form to the other is a mechanical process
In a function that operates on 3 structures, 2 are accessed with dot notation
There is one implicit structure, and two structures that need to be accessed with dot notation.
The scope resolution operator should be used every time you work with data structures and implement member function inside the structure definition.
The scope resolution operator need not be used everytime one works with structures and is used to implement member functions outside the class definition.
The this keyword is used to refer to the current object
The this keyword is a pointer to the current object.
What is the correct way to declare a member function called student_email outside the structure definition and takes a Student object as a parameter by reference?
struct Cube {
int mass;
int density;
//function to check if the current cude has a higher density than another
int greater_density(const Cube& cube2) {
if (density > cube2.density) {
return true;
}
else {
return false;
}
}
};
int main() {
Cube c;
Cube c1;
c.mass = 128;
c1.mass = 120
c.density = 2;
c1.density = 50;
cout << c.greater_density(c1) << endl;
}
True
The output of a bool is either a 0 or 1.
False
The output of a bool is either a 0 or 1.
0
Then density of c (2) is not greater than that of c1 (50).
The Student.cpp file will have the definitions of the member functions.
This is true!
Student.cpp needs to #include the header file.
This is true!
The Student.cpp file must implement the member functions in the same order as the declarations.
This is not necessary.
Header files contain the structure/function definitions and by splitting the program into multiple files one can compile the files seperately and link it to a single program later.
When we call a member function we invoke the function on the data structure
When called, the member function is invoked on the data structure
In a member function, you should declare the implicit parameter to be const before the parameter list
The implicit parameter should be declared const after the parameter list
In the example x::y the scope resolution operator indicates that a function named y can be invoked on a structure x
When defining a member function outside of the sturucture definition the :: operator is used to indicate that an object of that class type can call the function is question.
Implicit variable access in member functions allows us to access member variables without the dot notation
Correct! Implicit variable access allows us to access variables directly