1) Which of the Following Is Not a Type of Constructor?

Total Page:16

File Type:pdf, Size:1020Kb

1) Which of the Following Is Not a Type of Constructor? 1) Which of the following is not a type of 8) A variable defined within a block is visible constructor? A. From the point of definition onward in the A. Copy constructor program B. Friend constructor B. From the point of definition onward in the Answer:C. Default B constructor function D. Parameterized constructor C. From the point of definition onward in the Answer:block C D. Throughout the function 2) Which of the following is not the member of class? A. Static function 9) Which of the following term is used for a B. Friend function function defined inside a class? Answer:C. Const B function A. Member Variable D. Virtual function B. Member function Answer:C. Class B function D. Classic function 3) Which of the following concepts means determining at runtime what method to invoke? 10) Which of the following concept of oops A. Data hiding allows compiler to insert arguments in a B. Dynamic Typing function call if it is not specified? Answer:C. Dynamic C binding A. Call by value D. Dynamic loading B. Call by reference Answer:C. Default C arguments D. Call by pointer 4) The friend functions are used in situations where: A. We want to have access to unrelated classes 11) How many instances of an abstract class B. Dynamic binding is required can be created? C. Exchange of data between classes to take A. 1 Answer:place D B. 5 D. None of the above Answer:C. 13 D D. 0 5) The keyword friend does not appear in A. The class allowing access to another class 12) Which of the following cannot be friend? B. The class desiring access to another class A. Function Answer:C. The private C section of a class B. Class D. The public section of a class Answer:C. Object C D. Operator function 6) The term __________ means the ability to take many forms. 13) Which of the following concepts of OOPS A. Inheritance means exposing only necessary information to B. Polymorphism client? Answer:C. M emberB function A. Encapsulation D. Encapsulation B. Abstraction Answer:C. Data C hiding D. Data binding 7) C++ was originally developed by A. Clocksin and Melish B. Donald E.Knuth Answer:C. Sir D Richard Hadlee D. Bjarne Stroustrup 14) In structured programming, the problem is 21) Preventing direct access of data-members divided into various ______. of the class from outside world is known as A. modules ____. B. functions (A)Polymorphism Answer:C. structures B (B)Encapsulation D. objects Answer:(C)Data Hiding C (D) scope resolution. 15) In Object-oriented programming, the problem is divided into _____. A. classes & objects 22) What are cin and cout? B. functions (A) pointers Answer:C. structures A (B) functions D. modules Answer:(C) operator C (D) stream objects 16) A class is ____ datatype. A. primitive 23) Which header file must be included for cin B. derived and cout? Answer:C. user-defined C (A) stdio.h D. All of these (B) conio.h Answer:(C) iostream.h C (D) Both iostream.h and conio.h 17) A class is a collection of ____ and_____. (A)data-members & member functions (B)data-members, member functions and 24) Creating a new class using one or more main() existing classes is known as ____. (C) data-members, member functions,main() (A)Polymorphism Answer:and include A statements (B)Encapsulation (D)None of these Answer:(C)overloading D (D)inheritance 18) An object is ...... (A)a variable of class datatype. 25) Ability of an operator or function call to (B)same as a class. take different forms is known as ____. (C)just like a global variable. (A) Polymorphism Answer:(D)collection A of data-members and member (B) Encapsulation functions. Answer:(C) overloading A (D)inheritance 19) Wrapping up of data & functions together 26) cout is a/an __________ . in a class is known as _____. A. operator (A)Overloading B. function (B) Data Abstraction Answer:C. object C Answer:(C)Polymorphism D D. macro (D)Encapsulation 27) Which of the following concepts provides 20) Including only necessary details and facility of using object of one class inside ignoring additional details while defining a another class? class is known as ____. A. Encapsulation (A) Overloading B. Abstraction (B) Data Abstraction Answer:C. Composition C Answer:(C) Polymorphism B D. Inheritance (D) Encapsulation 34) Which of the following is correct about 28) How many types of polymorphisms are class and structure? supported by C++? A. class can have member functions while A. 1 structure cannot. B. 2 B. class data members are public by default Answer:C. 3 B while that of structure are private. D. 4 C. Pointer to structure or classes cannot be declared. Answer:D. class data D members are private by default 29) Which of the following is an abstract data while that of structure are public by default. type? A. int B. double 35) Which of the following concepts means Answer:C. string D wrapping up of data and functions together? D. Class A. Abstraction B. Encapsulation Answer:C. Inheritance B 30) A __________ is a special method used to D. Polymorphism initialize the instance variable of a class. A. Member function B. Destructor 36) Which of the following concepts means Answer:C. Constructor C waiting until runtime to determine which D. Structure function to call? A. Data hiding B. Dynamic casting 31) Which of the following concepts means Answer:C. Dynamic C binding adding new components to a program as it D. Dynamic loading runs? A. Data hiding B. Dynamic typing 37) Which of the following operator is Answer:C. Dynamic D binding overloaded for object cout? D. Dynamic loading A. >> B. << Answer:C. + B 32) Which of the following statement is D. = correct? A. A constructor is called at the time of declaration of an object. 39) Which of the following is the correct class B. A constructor is called at the time of use of of the object cout? an object. A. iostream C. A constructor is called at the time of B. istream declaration of a class. Answer:C. ostream C Answer:D. A constructor A is called at the time of use of a D. ifstream class. 40) Which of the following cannot be used with 33) Which of the following approach is adapted the keyword virtual? by C++? A. class A. Top-down B. member functions B. Bottom-up Answer:C. constructorC Answer:C. Right B -left D. destructor D. Left-right 41) Which of the following functions are performed by a constructor? 47) Which one of the following options is A. Construct a new class correct? B. Construct a new object A. Friend function can access public data Answer:C. Construct D a new function members of the class. D. Initialize objects B. Friend function can access protected data members of the class. C. Friend function can access private data 42) Which of the following is the correct way of Answer:members D of the class. declaring a function as constant? D. All of the above. A. const int ShowData(void) { /* statements */ } B. int const ShowData(void) { /* statements */ 48) Which of the following statements is } correct in C++? Answer:C. int ShowData(void) C const { /* statements */ } A. Classes cannot have data as protected D. Both A and B members. B. Structures can have functions as members. Answer:C. Class members B are public by default. 43) Which of the following statement is D. Structure members are private by default. correct? A. C++ allows static type checking. B. C++ allows dynamic type checking. 49) Which of the following access specifier is C. C++ allows static member function be of used as a default in a class definition? Answer:type const. D A. protected D. Both A and B. B. public Answer:C. private C D. friend 44) Which of the following header file includes definition of cin and cout? A. istream.h 50) What is correct about the static data B. ostream.h member of a class? Answer:C. iomanip.h D A. A static member function can access only D. iostream.h static data members of a class. B. A static data member is shared among all the object of the class. 45) What will happen if a class is not having C. A static data member can be accessed any name? Answer:directly from D main(). A. It cannot have a destructor. D. Both A and B. B. It cannot have a constructor. Answer:C. It isD not allowed. D. Both A and B. 51) Which of the following provides a reuse mechanism? A. Abstraction 46) Which one of the following is correct about B. Inheritance the statements given below? Answer:C. Dynamic B binding All function calls are resolved at compile- D. Encapsulation time in Procedure Oriented Programming. All function calls are resolved at compile- time in OOPS. 53) Which of the following statement is A. Only II is correct. correct? B. Both I and II are correct. A. Class is an instance of object. Answer:C. Only C I is correct. B. Object is an instance of a class. D. Both I and II are incorrect. Answer:C. Class B is an instance of data type. D. Object is an instance of data type. 59) Inline Functions are invoked at 53) The process of building new classes from A. Run time existing one is called B. Compile time A. Structure AnswerC. Depends: B on how it is invoked B. Inheritance D. Both b and c above Answer:C.
Recommended publications
  • C++ COPY CONSTRUCTOR Rialspo Int.Co M/Cplusplus/Cpp Co Py Co Nstructo R.Htm Copyrig Ht © Tutorialspoint.Com
    C++ COPY CONSTRUCTOR http://www.tuto rialspo int.co m/cplusplus/cpp_co py_co nstructo r.htm Copyrig ht © tutorialspoint.com The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to: Initialize one object from another of the same type. Copy an object to pass it as an arg ument to a function. Copy an object to return it from a function. If a copy constructor is not defined in a class, the compiler itself defines one.If the class has pointer variables and has some dynamic memory allocations, then it is a must to have a copy constructor. The most common form of copy constructor is shown here: classname (const classname &obj) { // body of constructor } Here, obj is a reference to an object that is being used to initialize another object. #include <iostream> using namespace std; class Line { public: int getLength( void ); Line( int len ); // simple constructor Line( const Line &obj); // copy constructor ~Line(); // destructor private: int *ptr; }; // Member functions definitions including constructor Line::Line(int len) { cout << "Normal constructor allocating ptr" << endl; // allocate memory for the pointer; ptr = new int; *ptr = len; } Line::Line(const Line &obj) { cout << "Copy constructor allocating ptr." << endl; ptr = new int; *ptr = *obj.ptr; // copy the value } Line::~Line(void) { cout << "Freeing memory!" << endl; delete ptr; } int Line::getLength( void ) { return *ptr; } void display(Line obj) { cout << "Length of line : " << obj.getLength() <<endl; } // Main function for the program int main( ) { Line line(10); display(line); return 0; } When the above code is compiled and executed, it produces the following result: Normal constructor allocating ptr Copy constructor allocating ptr.
    [Show full text]
  • Multi-Return Function Call
    To appear in J. Functional Programming 1 Multi-return Function Call OLIN SHIVERS and DAVID FISHER College of Computing Georgia Institute of Technology (e-mail: fshivers,[email protected]) Abstract It is possible to extend the basic notion of “function call” to allow functions to have multiple re- turn points. This turns out to be a surprisingly useful mechanism. This article conducts a fairly wide-ranging tour of such a feature: a formal semantics for a minimal λ-calculus capturing the mechanism; motivating examples; monomorphic and parametrically polymorphic static type sys- tems; useful transformations; implementation concerns and experience with an implementation; and comparison to related mechanisms, such as exceptions, sum-types and explicit continuations. We conclude that multiple-return function call is not only a useful and expressive mechanism, at both the source-code and intermediate-representation levels, but also quite inexpensive to implement. Capsule Review Interesting new control-flow constructs don’t come along every day. Shivers and Fisher’s multi- return function call offers intriguing possibilities—but unlike delimited control operators or first- class continuations, it won’t make your head hurt or break the bank. It might even make you smile when you see the well-known tail call generalized to a “semi-tail call” and a “super-tail call.” What I enjoyed the most was the chance to reimagine several of my favorite little hacks using the new mechanism, but this unusually broad paper offers something for everyone: the language designer, the theorist, the implementor, and the programmer. 1 Introduction The purpose of this article is to explore in depth a particular programming-language mech- anism: the ability to specify multiple return points when calling a function.
    [Show full text]
  • Aeroscript Programming Language Reference
    AeroScript Programming Language Reference Table of Contents Table of Contents 2 Structure of a Program 5 Comments 6 Preprocessor 7 Text Replacement Macro (#define/#undef) 7 Source File Inclusion (#include) 8 Conditional Inclusion (#if/#ifdef/#ifndef) 8 Data Types and Variables 11 Fundamental Data Types 11 Fundamental Numeric Data Types 11 Fundamental String Data Type 11 Fundamental Axis Data Type 11 Fundamental Handle Data Type 12 Aggregate Data Types 12 Array Data Types 12 Structure Data Types 13 Enumerated Data Types 14 Variables 15 Variable Declaration 15 Variable Names 15 Numeric, Axis, and Handle Variable Declaration Syntax 15 String Variable Declaration Syntax 15 Syntax for Declaring Multiple Variables on the Same Line 16 Array Variable Declaration Syntax 16 Structure Variable Definition and Declaration Syntax 16 Definition Syntax 16 Declaration Syntax 17 Member Access Syntax 17 Enumeration Variable Definition and Declaration Syntax 18 Definition 18 Declaration Syntax 19 Enumerator Access Syntax 19 Variable Initialization Syntax 20 Basic Variable Initialization Syntax 20 Array Variable Initialization Syntax 21 Structure Variable Initialization Syntax 22 Enumeration Variable Initialization Syntax 22 Variable Scope 23 Controller Global Variables 23 User-Defined Variables 23 User-Defined Variable Accessibility 23 User-Defined Local Variable Declaration Location 25 Variable Data Type Conversions 26 Properties 27 Property Declaration 27 Property Names 27 Property Declaration 28 Property Usage 28 Expressions 29 Literals 29 Numeric Literals
    [Show full text]
  • Concise Introduction to C++
    i i final3 2012/4/19 page 47 i i Chapter 2 Concise Introduction to C++ C++ seems to be most suitable for many practical applications. Indeed, C++ is sufficiently high-level to allow transparent object-oriented programming and efficient use of human resources, yet is also sufficiently low-level to have types, variables, pointers, arrays, and loops to allow efficient use of computer resources. In this chapter, we give a concise description of C++ and illustrate its power as an object-oriented programming language. In particular, we show how to construct and use abstract mathematical objects such as vectors and matrices. We also explain the notion of a template class, which can be filled with a concrete type later on in compilation time. We also discuss inheritance and illustrate its potential. 2.1 Objects As we have seen above, C is a language based on functions. Every command is also a function that returns a value that can be further used or abandoned, according to the wish of the programmer. Furthermore, programmers can write their own functions, which may also return variables of the type specified just before the function name. When the function is called, a temporary, unnamed variable is created to store the returned value until it has been used. C++, on the other hand, is an object-oriented programming language. In this kind of language, the major concern is not the functions that can be executed but rather the objects upon which they operate. Although C++ supports all the operations and features available in C, its point of view is different.
    [Show full text]
  • The Cool Reference Manual∗
    The Cool Reference Manual∗ Contents 1 Introduction 3 2 Getting Started 3 3 Classes 4 3.1 Features . 4 3.2 Inheritance . 5 4 Types 6 4.1 SELF TYPE ........................................... 6 4.2 Type Checking . 7 5 Attributes 8 5.1 Void................................................ 8 6 Methods 8 7 Expressions 9 7.1 Constants . 9 7.2 Identifiers . 9 7.3 Assignment . 9 7.4 Dispatch . 10 7.5 Conditionals . 10 7.6 Loops . 11 7.7 Blocks . 11 7.8 Let . 11 7.9 Case . 12 7.10 New . 12 7.11 Isvoid . 12 7.12 Arithmetic and Comparison Operations . 13 ∗Copyright c 1995-2000 by Alex Aiken. All rights reserved. 1 8 Basic Classes 13 8.1 Object . 13 8.2 IO ................................................. 13 8.3 Int................................................. 14 8.4 String . 14 8.5 Bool . 14 9 Main Class 14 10 Lexical Structure 14 10.1 Integers, Identifiers, and Special Notation . 15 10.2 Strings . 15 10.3 Comments . 15 10.4 Keywords . 15 10.5 White Space . 15 11 Cool Syntax 17 11.1 Precedence . 17 12 Type Rules 17 12.1 Type Environments . 17 12.2 Type Checking Rules . 18 13 Operational Semantics 22 13.1 Environment and the Store . 22 13.2 Syntax for Cool Objects . 24 13.3 Class definitions . 24 13.4 Operational Rules . 25 14 Acknowledgements 30 2 1 Introduction This manual describes the programming language Cool: the Classroom Object-Oriented Language. Cool is a small language that can be implemented with reasonable effort in a one semester course. Still, Cool retains many of the features of modern programming languages including objects, static typing, and automatic memory management.
    [Show full text]
  • Things I Learned from the Static Analyzer
    Things I Learned From The Static Analyzer Bart Verhagen [email protected] 15 November 2019 Static code analyzers What can they do for us? Developer High level structure Low level details Static code analyzer Expertise Static code analyzers Focus areas • Consistency • Maintenance • Performance • Prevent bugs and undefined behaviour Static code analyzers Used static code analyzers for this talk • clang-tidy • cppcheck Consistency ??? ??? #include "someType.h" class Type; template<typename T> class TemplateType; typedef TemplateType<Type> NewType; Consistency Typedef vs using Typedef vs using #include "someType.h" class Type; template<typename T> class TemplateType; typedef TemplateType<Type> NewType; using NewType = TemplateType<Type>; // typedef TemplateType<T> NewTemplateType; // Compilation error template<typename T> using NewTemplateType = TemplateType<T>; modernize-use-using Warning: use ’using’ instead of ’typedef’ The Clang Team. Clang-tidy - modernize-use-using. url: https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-using.html Maintenance ??? ??? class Class { public: Class() : m_char('1'), m_constInt(2) {} explicit Class(char some_char) : m_char(some_char), m_constInt(2) {} explicit Class(int some_const_int) : m_char('1'), m_constInt(some_const_int) {} Class(char some_char, int some_const_int) : m_char(some_char), m_constInt(some_const_int) {} private: char m_char; const int m_constInt; }; Maintenance Default member initialization Default member initialization class Class { public: Class() : m_char('1'), m_constInt(2)
    [Show full text]
  • C Programming Tutorial
    C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i COPYRIGHT & DISCLAIMER NOTICE All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] ii Table of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ............................................................................................ 3 Installation on Unix/Linux ............................................................................
    [Show full text]
  • Copy Elision in Exception Handling
    Document Number: J16/04-0165 = WG21 N1725 Date: 2004-11-08 Reply to: William M. Miller Edison Design Group, Inc. [email protected] Copy Elision in Exception Handling I. The Problem Clause 15 has two passages dealing with copy elision in exception handling. 15.1¶5 says, If the use of the temporary object can be eliminated without changing the meaning of the program except for the execution of constructors and destructors associated with the use of the temporary object (12.2), then the exception in the handler can be initialized directly with the argument of the throw expression. When the thrown object is a class object, and the copy constructor used to initialize the temporary copy is not accessible, the program is ill-formed (even when the temporary object could otherwise be eliminated). Similarly, if the destructor for that object is not accessible, the program is ill-formed (even when the temporary object could otherwise be eliminated). In a sometimes overlapping, sometimes differing passage, 15.3¶17 says, If the use of a temporary object can be eliminated without changing the meaning of the program except for execution of constructors and destructors associated with the use of the temporary object, then the optional name can be bound directly to the temporary object specified in a throw-expression causing the handler to be executed. The copy constructor and destructor associated with the object shall be accessible even when the temporary object is eliminated. Part of the difference is terminological. For instance, 15.1¶5 refers to “the exception in the handler,” while the “optional name” in 15.3¶17 is a reference to the exception-declaration that is part of a handler (15¶1).
    [Show full text]
  • Functions in C
    Functions in C Fortran 90 has three kinds of units: a program unit, subroutine units and function units. In C, all units are functions. For example, the C counterpart to the Fortran 90 program unit is the function named main: #include <stdio.h> main () /* main */ f float w, x, y, z; int i, j, k; w = 0.5; x = 5.0; y = 10.0; z = x + y * w; i = j = k = 5; printf("x = %f, y = %f, z = %f n", x, y, z); printf("i = %d, j = %d, k = %dnn", i, j, k); /* main */ n g Every C program must have a function named main; it’s the func- tion where the program begins execution. C also has a bunch of standard library functions, which are functions that come predefined for everyone to use. 1 Standard Library Functions in C1 C has a bunch of standard library functions that everyone gets to use for free. They are analogous to Fortran 90’s intrinsic functions, but they’re not quite the same. Why? Because Fortran 90’s intrinsic functions are built directly into the language, while C’s library functions are not really built into the language as such; you could replace them with your own if you wanted. Here’s some example standard library functions in C: Function Return Type Return Value #include file printf int number of characters written stdio.h Print (output) to standard output (the terminal) in the given format scanf int number of items input stdio.h Scan (input) from standard input (the keyboard) in the given format isalpha int Boolean: is argument a letter? ctype.h isdigit int Boolean: is argument a digit? ctype.h strcpy char [ ] string containing copy string.h Copy a string into another (empty) string strcmp int comparison of two strings string.h Lexical comparison of two strings; result is index in which strings differ: negative value if first string less than second, positive if vice versa, zero if equal sqrt float square root of argument math.h pow float 1st argument raised to 2nd argument math.h 1 Brian W.
    [Show full text]
  • Object Oriented Programming COP3330 / CGS5409  C++ Automatics ◦ Copy Constructor () ◦ Assignment Operator =  Shallow Copy Vs
    Object Oriented Programming COP3330 / CGS5409 C++ Automatics ◦ Copy constructor () ◦ Assignment operator = Shallow copy vs. Deep copy DMA Review c-strings vs. concept of string class Constructor Destructor Copy Constructor Assignment operator = if you do not explicitly define one in a class, a default version will automatically be built for you by the compiler The automatic versions of the constructor and destructor don't do anything, but they will be there if you do not build them. The constructor you get is the "default constructor" -- no parameters – The automatic versions of the Copy Constructor and the Assignment operator overload are similar to each other, and their default versions are always built in a standard way. A copy constructor IS a constructor, so it is a function with the same name as the class and no return type (just like any constructor). However, it is invoked implicitly when something is done that causes a COPY of an existing object to be created. This happens when: ◦ An object is defined to have the value of another object of the same type ◦ An object is passed by value into a function ◦ An object is returned (by value) from a function Here's an example of item #1 in the above list: Fraction f1, f2(3,4); // declaration of two //fractions Fraction f3 = f2; // declaration of f3 being // initialized as a copy of f2 Note: This last line of code calls the copy constructor, since the initialization is on the same line as the declaration of f3. Contrast this with the following: f1 = f2; // this uses the assignment // operator, since f1 and f2 already exist Since the purpose of a copy constructor is to not only initialize the data in an object, but to initialize it as a copy of another existing object, the original object must be passed in as a parameter.
    [Show full text]
  • The Rule of the Big Five
    C++11: The Rule of the Big Five Resource Management The dynamic creation and destruction of objects was always one of the bugbears of C. It required the programmer to (manually) control the allocation of memory for the object, handle the object’s initialisation, then ensure that the object was safely cleaned-up after use and its memory returned to the heap. Because many C programmers weren’t educated in the potential problems (or were just plain lazy or delinquent in their programming) C got a reputation in some quarters for being an unsafe, memory-leaking language. C++ improved matters significantly by introducing an idiom known (snappily) as RAII/RRID – Resource Acquisition Is Initialisation / Resource Release Is Destruction*. The idiom makes use of the fact that every time an object is created a constructor is called; and when that object goes out of scope a destructor is called. The constructor/destructor pair can be used to create an object that automatically allocates and initialises another object (known as the managed object) and cleans up the managed object when it (the manager) goes out of scope. This mechanism is generically referred to as resource management. A resource could be any object that required dynamic creation/deletion – memory, files, sockets, mutexes, etc. Resource management frees the client from having to worry about the lifetime of the managed object, potentially eliminating memory leaks and other problems in C++ code. However, RAII/RRID doesn’t come without cost (to be fair, what does?) Introducing a ‘manager’ object can lead to potential problems – particularly if the ‘manager’ class is passed around the system (it is just another object, after all).
    [Show full text]
  • Copy Constructors
    Copy Constructors • Shallow Copy: – The data members of one object are copied into the data members of another object without taking any dynamic memory pointed to by those data members into consideration. (“memberwise copy”) • Deep Copy: – Any dynamic memory pointed to by the data members is duplicated and the contents of that memory is copied (via copy constructors and assignment operators -- when overloaded) Copy Constructors • In every class, the compiler automatically supplies both a copy constructor and an assignment operator if we don't explicitly provide them. • Both of these member functions perform copy operations by performing a memberwise copy from one object to another. • In situations where pointers are not members of a class, memberwise copy is an adequate operation for copying objects. • However, it is not adequate when data members point to memory dynamically allocated within the class. Copy Constructors • Problems occur with shallow copying when we: – initialize an object with the value of another object: name s1; name s2(s1); – pass an object by value to a function or when we return by value: name function_proto (name) – assign one object to another: s1 = s2; Copy Constructors • If name had a dynamically allocated array of characters (i.e., one of the data members is a pointer to a char), – the following shallow copy is disastrous! n am e sm it h ("Su e Sm it h "); / / on e ar g con st r u ctor u sed n am e clon e(sm it h ); / / d efau lt cop y con st r u ctor u sed smith clone ptr S ptr u length=10 length=10 e S m i t h '\0' Copy Constructors • To resolve the pass by value and the initialization issues, we must write a copy constructor whenever dynamic member is allocated on an object-by-object basis.
    [Show full text]