What are the advantages and disadvantages of employing the using directive?

1 Answer

Answer :

The using-directive is often confused with a using-declaration. A using-declaration adds a given name to a local scope whereas a using-directive does not; it simply makes names accessible in the scope in which they were declared. For example:namespace X { int i=0, j=0, k=0; }int k=42; // global scope// using-directive example:void f1 (void) {int i=0; // local scopeusing namespace X; // make names from X accessiblei++; // local ij++; // X::jk++; // error: X::k or global k?::k++; // global kX::k++; // X::k}// using-declaration example:void f2 (void) {int i=0; // local scopeusing X::i; // error: i declared twice!using X::j; // okusing X::k; // hides global ki++;j++; // X::jk++; // X::k}Polluting the global namespace should always be avoided in non-trivial applications, however we often encounter tutorial code with an implied using namespace std; directive in the global scope to help the student focus on the actual code. We would never do this in production code. Ideally, the only name that should ever be visible in the global scope is the global main function. Everything else should ideally be put in their own namespaces and only imported into a local scope as and when they are actually needed. If we should require additional names to be accessible in the global scope, then these should be limited to just those names which represent truly global concepts.Large programs tend to use a lot of namespaces and it can be tedious typing them out in full, particularly when they are nested or long and descriptive names. A using-declaration (at local scope) helps us to isolate just those names we are actually interested in, but if we need to use a lot of names from the same namespace, a using-directive helps cut down on the verbosity.Namespace aliases are also useful for reducing long, descriptive names to a less verbose form in order to aid readability:namespace American_Telephone_and_Telegraph { /* ... */ } // too long// ...namespace ATT = American_Telephone_and_Telegraph; // aliasYou might ask why the programmer didn't simply use ATT in the first place, but short names greatly increase the risk of a name-clash. Thus it is better for the programmer to introduce shorthand aliases as and when they are actually required.Naturally, we should avoid using-directives, using-declarations and namespace aliases in headers, because we cannot predict exactly where those names might be included, resulting in namespace pollution that can lead to some very obscure or subtle errors that would be difficult to track down.

Related questions

Description : Which one of the following best describes project management? a. Using APM's Body of Knowledge 6th edition as a guide to all projects. b. Employing a project manager who has undertaken similar ... on a project full time. d. Application of processes and methods throughout the project life cycle.

Last Answer : d. Application of processes and methods throughout the project life cycle.

Description : Which one of the following illustrates why effective project management is beneficial to an organization? a. It utilizes resources as and when required under direction of a project manager. b. ... d. It ensures that the chief executive is accountable for the achievement of the defined benefits.

Last Answer : a. It utilizes resources as and when required under direction of a project manager.

Description : Which one of the following best describes project management?  a. Using APM's Body of Knowledge 6th edition as a guide to all projects.  b. Employing a project manager who has undertaken ... on a project full time. d. Application of processes and methods throughout the project life cycle.

Last Answer : d. Application of processes and methods throughout the project life cycle.

Description : Marketers can enhance the consumer's ability to access knowledge structures by 1. Using loud music 2. Using colorful ads 3. Employing verbal framing 4. Repeating brand information 5. None of these

Last Answer : Employing verbal framing

Description : Ramesh is a student of standard X. He organized many activities in his school to convey the students about the various advantages and disadvantages of using renewable and non-renewable sources of energy. Many ... of energy. (in) Which two values are reflected in Ramesh's thought and action? -Science

Last Answer : (i) Activities that Ramesh have had assigned for the students are: (a) Hands on projects related to renewable and non-renewable sources of energy. (b) Photograph exhibitions on the topic ... of renewable source of energy. Ramesh’s action: Concern for community advantage and good management.

Description : What are the advantages and disadvantages of using a silicon made bong instead of a standard glass bong?

Last Answer : So, glass is cheaper and more breakable than silicone, but it's also cleaner. While silicone is virtually indestructable and very flexible (and easy to hide in most places), sometimes the silicone ... would consider a bigger advantage or disadvantage based on what you are looking for in a bong.

Description : What are the advantages and disadvantages of sparse matrix using array?

Last Answer : Feel Free to Answer

Description : what are the advantages and disadvantages of using inbound call center services for big businesses?

Last Answer : Some of the advantages of using inbound call center services is that it saves valuable time and resourses and it also boosts sales. Some of the disadvantages are that sometimes you don't end up with the most skilled or business like conduct or services as you would like to have.

Description : What are the advantages and disadvantages of using contact lens?

Last Answer : Some of the adventages are wider field of view and better with asymmetrical prescriptions. Some of the disadvantages are high maintenance costs and long time required for fitting and adaptation.

Description : What are the advantages and disadvantages of using breast pumps?

Last Answer : There are many different advantages and disadvantages when it comes to have a breast pump. It could be good so that you can empty the milk in the bottle and take it on the go and it also could be very painful.

Description : What are the cloud computing advantages and disadvantages of using it?

Last Answer : An advantage of cloud computing is to be able to access this product from multiple locations. A disadvantage is that cloud computing is harder to secure.

Description : What are some advantages and disadvantages for using a professional party planner for an engagement party?

Last Answer : There are many disadvantages and advantages to hiring a party planner. The advantage is that you do not have to do any of the work. The disadvantage is that a professional is very expensive.

Description : Briefly discuss the advantages and disadvantages of using typed DataSet objects.

Last Answer : Typed DataSet objects allow you to work with data that is represented as members of the .NET common type system. This allows your applications to be aware of the types of data returned in a DataSet and serves ... if you do not know the structure of your data, and can be used with any data source. 

Description : Describe Briefly The Advantages And Disadvantages Of Using Plastic And Timber Fenders?

Last Answer : Answer : The advantages and disadvantages of using plastic fenders are as follows: Plastic fenders are low in strength with a relatively high resistance to abrasion. Plastic fenders are resistant ... of contact. Also since they are made from recycled material they are environmental friendly.

Description : What are the advantages and disadvantages of using gear pumps?

Last Answer : Gear pumps are a type of positive displacement pump that are appropriate for pumping relatively high pressures and low capacities. Advantages include the ability to handle a wide range of viscosities ... controlled via the motor speed. Throttling the discharge is not an acceptable means of control.

Description : Draw and explain temperature measurement using RTD. State its advantages and disadvantages.

Last Answer : https://youtu.be/rYcglFW4y0I

Description : Explain the advantages and disadvantages of using memory I/O and standard I/O.

Last Answer : Memory mapped I/O and standard I/O are the two methods for communicating microprocessor with peripherals. Processor talks to both memory and peripheral using the same bus.Two ways to talk to a peripheral. ... of standard I/O is no loss of memory addresses to the use as I/O addresses.

Description : Which of the following is not a program linking directive i) EXTRN ii) SEGMENT iii) NAME iv) PUBLIC v) USING a) iv, v b) ii, iii c) i, iii d) ii, v

Last Answer : c) i, iii

Description : Any sites or info on employing ex-felons?

Last Answer : answer:Are you looking for a list of employers that will hire someone on probation or parole or are you looking for general information on how people with a felony find employment? If it’s the former, knowing where you’re located would help.

Description : If a human fertilized egg/fetus had the same legal rights as a person, should employing a pregnant woman be illegal?

Last Answer : answer:I think the people who would grant an embryo legal status would probably agree with you. They don't like women, much less pregnant women, working. You can also say the embryo is entitled ... the people that would propose this. This is what happens when poor thinking tries to impose itself.

Description : What would be the economic and environmental impact of employing a sheep to "mow" a four acre lawn?

Last Answer : Sounds like a win/win to me.

Description : Turning a disability into a gift - What do you think about employing blind people to help detect breast cancer?

Last Answer : Sounds amazing. If it works, then they should use it as much as possible.

Description : Explain the following: In the seventeenth century, merchants from towns in Europe began employing peasants and artisans within the villages. -SST 10th

Last Answer : In the seventeenth century, the trade and commerce guild controlled the market, raw materials, employees, and also production of goods in the towns. World trade expanded at very fast rate during ... by employing more men. Therefore, they turned to peasants and artisans who lived in villages.

Description : Explain why the seventeenth century merchants from towns in Europe began employing peasants and artisans within the village. -SST 10th

Last Answer : Merchants preferred employing peasants and artisans within the village because it was difficult to open new businesses in towns and cities where the guilds were very much organised. They ... between the new merchants and farmers were closer even though they lived in different environments.

Description : Employing a live in maid?

Last Answer : The world is growing to something very scary as human beings are not longer trusted any more. In the 80's and 90's in my country people were very comfortable with employing maids to work ... you will have to sign some agreements with the agents and a comprehensive background check should be done.

Description : When employing local national support appropriate security measures should be taken?

Last Answer : Ensure that contracted linguists do not jeopardize operationsthrough espionage.

Description : Who used the thousand years as an equivalent for the whole duration of the world employing the number of perfection to mark the fullness of time' according to St Augustine's 'City of God'?

Last Answer : The duration of this earth iteration (age) is clearly given in the texts of the KJV bible. 2nd Peter Ch 3 states a day with the Lord is a 1000 years with man. Therefore the first 7 days mentioned ... come at the end of this earth iteration, upon this 6th day of this second week which we are within,

Description : As part of a robust design, you would expect to find use of modular architectures employing open systems for selected key interfaces?

Last Answer : ,,,

Description : The purity of an isolated protein can be tested by employing various methods. (A) Solubility curve (B) Molecular weight (C) Ultra Centrifugation (D) Immuno Ractivity (E) All of these

Last Answer : Answer : C

Description : Which of the following statements about septic shock are true? A. A circulating myocardial depressant factor may account for the cardiac dysfunction sometimes seen with shock due to sepsis or ... animal studies that demonstrate a significant improvement in survival with the use of such agents.

Last Answer : Answer: AB DISCUSSION: Shock due to sepsis or SIRS frequently manifests as a hyperdynamic cardiovascular response, consisting of an elevated CI and a decreased SVR or SVRI. Occasionally, ... been encouraging thus far in human clinical trials, despite the promising results from many animal studies

Description : In multi stage compressor, the isothermal compression is achieved by A. Employing intercooler B. By constantly cooling the cylinder C. By running compressor at very slow speed D. By insulating the cylinder

Last Answer : ANSWER : C

Description : An employer goes on employing more and more of a factor units until : (1) the Average Revenue Productivity becomes equal to Marginal Revenue Productivity. (2) the Marginal Revenue Productivity becomes ... into operation. (4) the Marginal Revenue Productivity of a factor becomes equal to its reward.

Last Answer : (4) the Marginal Revenue Productivity of a factor becomes equal to its reward. Explanation: 'According to the Marginal Productivity Theory, the reward or the price of a factor unit depends upon its ... marginal cost of the factor is greater than MRP, it will reduce employment to reduce its loss.

Description : Which of the following polymers are produced by employing all bulk polymerisation, solution polymerisation & suspension polymerisation technique of addition (chain) polymerisation (A) PVC (B) Bakelite (C) PTFE (D) Epoxy resin

Last Answer : (A) PVC

Description : . Polyvinyl chloride (PVC) is (A) A thermosetting material (B) A condensation polymerisation product (C) Made by employing emulsion polymerisation (D) None of these

Last Answer : (C) Made by employing emulsion polymerisation

Description : SBR is produced by the copolymerisation of butadiene & styrene by employing emulsion polymerisation. The weight ratio of styrene and butadiene is maintained at (A) 1: 3 (B) 3 : 1 (C) 1 : 2 (D) 2 : 1

Last Answer : (A) 1: 3

Description : The cake resistance increases steadily with the time of filtration in a plate and frame filter employing constant __________ filtration. (A) Rate (B) Pressure (C) Both (A) & (B) (D) Neither (A) nor (B

Last Answer : (C) Both (A) & (B)

Description : Sorting classifiers employing differential settling methods forseparation of particles make use of the differences in their (A) Particle sizes (B) Densities (C) Terminal velocities (D) None of these

Last Answer : (C) Terminal velocities

Description : Pick out the wrong statement. (A) For the compressible cake, voidage & the specific resistance of the cake can be assumed to be constant (B) Cake resistance is independent of the pressure ... Crushing of explosive materials are done by employing dry-grinding (D) Gyratory crusher is a coarse crusher

Last Answer : (B) Cake resistance is independent of the pressure drop

Description : The process employing desorption of the absorbed solute by a solvent is called (A) Elution (B) Osmosis (C) Reverse osmosis (D) Sublimation

Last Answer : (A) Elution

Description : .'Voluntarily' has been defined as an effect caused by means whereby a person  intended to cause it or by means, at the time of employing those means, know or had  reason to believe to be likely to cause it under (a) Section 39 (b) Section 38 (c) Section 37 (d) Section 40.

Last Answer : (a) Section 39

Description : Heat sensitive materials can be concentrated in an evaporator employing (A) Vacuum (B) High pressure (C) High residence time (D) None of these

Last Answer : (A) Vacuum

Description : Heat sensitive materials can be concentrated in an evaporator employing (A) Vacuum (B) High pressure (C) High residence time (D) None of these

Last Answer : (A) Vacuum

Description : Which of the following statements concerning the intended user of a professional accountant's report is incorrect? a. The responsible party and the intended user may both be within the same organization. b. ... may be established by law. d. The responsible party may also be one of the intended users

Last Answer : The intended user should never be established by agreement between the practitioner and the responsible party or those engaging or employing the practitioner

Description : Which of the following statements concerning the intended user of a professional accountant's report is incorrect? a. The responsible party and the intended user may both be within the same organization. b. ... be established by law. d. The responsible party may also be one of the intended users.

Last Answer : The intended user should never be established by agreement between the practitioner and the responsible party or those engaging or employing the practitioner

Description : ICT has been an essential necessity for i) Communication at long distances ii) Employing IT and its services to the rural areas iii) Providing medical help to nurses and staffs for treatments iv) All of these

Last Answer : iv) All of these

Description : In a furnace employing forced draught as compared to induced draught, (A) Air is sucked in, so air leaks are more and hence the furnace efficiency is reduced (B) The fan operates hot and hence blades are liable to corrosion and erosion (C) Positive pressure exists in the furnace (D) None of these

Last Answer : (C) Positive pressure exists in the furnace

Description : Test specimen for determination of refractoriness under load (RUL) of a refractory is heated in a (A) Furnace employing neutral atmosphere (B) Carbon resistance furnace (C) Reducing atmosphere (D) Furnace employing negative pressure

Last Answer : (B) Carbon resistance furnace

Description : Furnace oil consumption in a furnace for a given duty employing preheated combination air (at 300°) may be reduced by about __________ percent as compared to the use of atmospheric combustion air. (A) 5 (B) 10 (C) 20 (D) 35

Last Answer : (C) 20