Question

In: Computer Science

What is the advantage of defining the member functions outside a class rather than defining inside...

What is the advantage of defining the member functions outside a class rather than defining inside a class?

How the following are achieved in C++?

a) static polymorphism.

b) dynamic polymorphism

What will happen if you forget to implement the pure virtual function in the derived class?

How a function templates differs from function overloading?

Solutions

Expert Solution

Now we will see the solution of each question one by one
Let take the first one
1. Functions can be defined or declared inside the class definition. But Many functions have very large defintion that makes it complex to readable.In this case we can define the class outside the class using scope resolution operator.
So the flexiblity of code is the biggest advantages

2. We know that Polymorphism means many form. Now here we have two types of polymorphism
a. Static polymorphism or we can say it as compile time polymorphism. Now this type of polymorphism can be achieved by function overloading and operator overloading.
In function overloading we have multiple function with same name but different parameters.
now in operator overloading we can make single operator to perform multiple operations.

b. Dynamic polymorphism is also called as run time polymorphism. And it can be achieved by function overriding.
In function overriding we have multiple function with same name and same arguments. but they are defined in different classes.

3. If you forget to implement the pure virtual function in the derived class, then derived class becomes the abstract class. while compilation we get a error like this:
  

Compiler Error: cannot declare variable 'variable_name' to be of abstract type 
'Derived'  because the following virtual functions are pure within
'Derived': virtual void Base::function_name() 

4. We know that both funtion overloading and template are the types of Polymorphism.Now template is better if we provide same action on different types.That means template can operate on any data.In function overloading we have multiple functions with same name and different arguments.
That means function overloading is used when multiple functions do similar operations. but in function template multiple functions do identical operation.

In case you face any difficulty for the soution, let me know in the comment section.

Related Solutions

Rather than play outside with friends, Aaron once preferred to sit inside watching TV and munching...
Rather than play outside with friends, Aaron once preferred to sit inside watching TV and munching on chips. As a result, he has become obese. He is now determined to lose excess weight with a reduced-calorie diet. Aaron is likely to have difficulty losing weight while dieting because a. low-calorie diets trigger increased secretions of leptin. b. his resting metabolic rate will increase and cause him to overeat. c. it takes less food intake to maintain fat than it did...
What is the advantage of using max wavelength rather than the wavelength nearby such as 580...
What is the advantage of using max wavelength rather than the wavelength nearby such as 580 nm? This is for the Bradford protein assay where the maximum of the absorbance spectrum is at 595 nm.
What is a major economic advantage of producing therapeutic proteins in plants rather than in bioreactors...
What is a major economic advantage of producing therapeutic proteins in plants rather than in bioreactors filled with microbes or mammalian cells?
If a cell has less concentration of solutes inside than outside, it is in a(n) ___________...
If a cell has less concentration of solutes inside than outside, it is in a(n) ___________ environment. Hypertonic Isotonic Hypotonic Mesotonic
The concentration of CO2 is lower inside a plant cell than in the atmosphere (outside the...
The concentration of CO2 is lower inside a plant cell than in the atmosphere (outside the cell). In your own words, describe how the CO2 levels are kept low inside the plant cell and explain why this is necessary. Assume the outer surface of the leaves of this plant have a waxy layer.
Which of the following is not an advantage of a company using equity rather than debt...
Which of the following is not an advantage of a company using equity rather than debt to finance a project? A. Interest always takes more cash than does paying dividends. B. Dividends do not need to be paid. C. Equity does not need to be repaid whereas debt does. D. Interest and Dividends are tax deductible. A note of caution in interpreting the debt ratio is that A. all debt decreases liquidity ratios. B. financing arrangements, such as leases, may...
class rather than ethnicity is responsible for stratification in the Caribbean.
class rather than ethnicity is responsible for stratification in the Caribbean.
In C++ please Your class could have the following member functions and member variables. However, it's...
In C++ please Your class could have the following member functions and member variables. However, it's up to you to design the class however you like. The following is a suggestion, you can add more member variables and functions or remove any as you like, except shuffle() and printDeck(): (Note: operators must be implemented) bool empty(); //returns true if deck has no cards int cardIndex; //marks the index of the next card in the deck Card deck[52];// this is your...
I want the code below to be edited: Rather than giving the input string inside the...
I want the code below to be edited: Rather than giving the input string inside the code, I want the program to ask the user for an input and calculate and complete this code. I have pasted the actual code below, Please edit the input section only so that I can input any string or any sentence as I like. The program must ask the user that "Enter a string/sentence" and take the data to calculate the Huffman code. #include...
what is Comparative Advantage? what is absolute advantage? what would you rather have a comparative or...
what is Comparative Advantage? what is absolute advantage? what would you rather have a comparative or absolute advantage with trading?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT