Abstraction Classes
Abstract classes go about as articulations of general ideas from which more explicit classes can be determined. You can't make a theoretical class kind of article. In any case, you can utilize spots and references for conceptual class types.
You make a theoretical class by announcing at any rate one unadulterated virtual part work. It is a virtual capacity announced utilizing the unadulterated specifier (= 0) language structure. The classes got from the theoretical class should carry out an unadulterated virtual capacity or they are additionally, dynamic classes. Data abstraction Consider the model introduced in virtual undertakings. The class account is intended to give regular usefulness, however type account objects are too basic to be in any way valuable. This implies that a decent record is a decent possibility for a theoretical class: C ++ Duplicate /deriv_AbstractClasses.cpp /arrange: with/ld Class account { public: Record (twofold D);/constructor. Virtual twofold getBalance ();/Get the equilibrium. Virtual void PrintBalance () = 0;/unadulterated virtual capacity. Private: Twofold _ awkwardness; }; The lone distinction between this presentation and the past one is that PrintBalance is pronounced with an unadulterated specifier (= 0). Limitation on theoretical classes Theoretical class can't be utilized for: Variable or part information Sorts of rationale Capacity bring type back Sorts of express changes In the event that the constructor for a theoretical class straightforwardly or by implication calls an unadulterated virtual capacity, the outcome is vague. In any case, constructors and destructors for theoretical classes can call other part works. Characterized unadulterated virtual capacities In theoretical classes unadulterated virtual capacities can be characterized, or their execution. You can say just such capacities utilizing completely qualified sentence structure: Conceptual class-name :: work name () Characterized unadulterated virtual capacities are useful when you configuration class chains of importance whose base classes incorporate unadulterated virtual destructors. The explanation behind this is that base class destructors are constantly called during object annihilation. Think about the accompanying model: C ++ Duplicate /deriv_RestrictionsOnUsingAbstractClasses.cpp /Declare a theoretical base class with an unadulterated virtual destroyer. /This is the easiest conceivable unique class. Class base {{ public: base () {} Virtual ~ base () = 0 {};/unadulterated virtual, and characterize! }; Class subsidiary: public base {{ public: eliminated () {} ~ Derivative () {} }; INT primary() {{ Subordinate aDerived;/Destroyer is called when it leaves scope } The model shows the meaning of ~ base () inline, yet you can likewise characterize it by a class outside of base :: ~ base () {}. At the point when an article is pushed out of extension, the destroyer is known as a class subsidiary. The compiler creates code to call the destroyer for the class base followed by the determined destroyer. Void execution ~ reason for an unadulterated virtual capacity guarantees that probably some execution exists for the capacity. Without it, the linker produces an uncertain outer image blunder for the hidden call.
Visit: https://www.chlopadhe.com/data-abstraction-in-c-plus-plus/
Comments
Post a Comment